{"id":71096,"date":"2019-05-13T11:00:22","date_gmt":"2019-05-13T08:00:22","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=71096"},"modified":"2021-11-07T23:29:37","modified_gmt":"2021-11-07T21:29:37","slug":"sql-data-types-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/","title":{"rendered":"SQL Data Types Tutorial"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\"><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p><strong>SQL<\/strong> is the language used to communicate with <strong>Relational Databases<\/strong> such as MySQL, Oracle, MS SQL Server, PostgreSQL, etc. In this post, we will examine the various <strong>SQL Data Types<\/strong> and provide examples for MySQL, which is the most widely used open-source database. This post requires some knowledge in SQL and a tutorial for a complete understanding of SQL is found <a rel=\"noreferrer noopener\" aria-label=\"here (opens in a new tab)\" href=\"https:\/\/www.javacodegeeks.com\/2016\/03\/10-easy-steps-complete-understanding-sql.html\" target=\"_blank\">here<\/a>.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#prerequisites\">2. Prerequisites<\/a><\/dt>\n<dt><a href=\"#sql_basics\">3. SQL Basics<\/a><\/dt>\n<dt><a href=\"#sql_data_types\">4. SQL Data Types<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#numeric_data_types\">4.1 Numeric<\/a><\/dt>\n<dt><a href=\"#character_data_types\">4.2 Character<\/a><\/dt>\n<dt><a href=\"#data_time_data_types\">4.3 Date and Time<\/a><\/dt>\n<dt><a href=\"#json_xml_data_types\">4.4 JSON \/ XML<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#best_practices\">5. Best Practices<\/a><\/dt>\n<dt><a href=\"#conclusion\">6. Conclusion<\/a><\/dt>\n<dt><a href=\"#download_sql\">7. Download the SQL commands<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-2-prerequisites\"><a name=\"prerequisites\"><\/a>2. Prerequisites<\/h2>\n<h3 class=\"wp-block-heading\" id=\"h-install-mysql\">Install MySQL<\/h3>\n<p>To run the examples we will have to install the <strong>MySQL Community Server<\/strong> and use the <strong>MySQL Command-Line Client<\/strong> to interact with it. The MySQL version we will use is 5.7.26. From <a rel=\"noreferrer noopener\" aria-label=\"this (opens in a new tab)\" href=\"https:\/\/dev.mysql.com\/downloads\/mysql\/5.7.html#downloads\" target=\"_blank\">this<\/a> link, download the MySQL Community Server 5.7.26 for your operating system and follow the installation instructions. Once MySQL is installed, you should be prompted to change the root password. Do not forget that password as it will be the only way to login to MySQL. Finally, MySQL should automatically start as a service.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-create-test-database\">Create Test Database<\/h3>\n<p>The MySQL Command-Line Client comes with the MySQL Community Server so you won&#8217;t have to install any additional application. To run the examples of this post, we will execute SQL commands through the MySQL Command-Line Client. Before running any example, we would have to login to MySQL and create a new test database and table, in which we will run all our examples. <\/p>\n<h4 class=\"wp-block-heading\" id=\"h-login-to-mysql\">Login to MySQL<\/h4>\n<p>Open a terminal window and run the following command to login to MySQL:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Login to MySQL<\/em><\/span><\/p>\n<pre class=\"brush:bash\">$ mysql -u root -p\n<\/pre>\n<p>This login command uses the <strong>root<\/strong> user, which is the default root user for MySQL. After that, you will be prompted to enter the password you set when you installed MySQL. Upon successful login you will see the following welcome message:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Output<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Welcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 4\nServer version: 5.7.26 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2019, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n<\/pre>\n<p>Congratulations, you successfully logged in to MySQL and you can use the MySQL Command-Line Client to execute SQL commands. The next step would be to create a test database.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-create-a-test-database\">Create a Test Database<\/h4>\n<p>The test database will be used to run the examples of this post. In the MySQL Command-Line Client run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Create new empty database<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; create database test;\nQuery OK, 1 row affected (0.00 sec)\n<\/pre>\n<p>The above command will create a database named <strong>test<\/strong> and output that the operation was successful. To confirm that the database was created run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Show all databases<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; show databases;\n+--------------------+\n| Database           |\n+--------------------+\n| information_schema |\n| mysql              |\n| performance_schema |\n| sys                |\n| test               |\n+--------------------+\n5 rows in set (0.00 sec)\n<\/pre>\n<p>The <strong>show databases<\/strong> command shows all the databases created for MySQL. The output shows that our <strong>test<\/strong> database was successfully created. Finally, to use the test database we need to run the following command:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Switch to test database<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; use test;\nDatabase changed\n<\/pre>\n<p>We have now switched to the test database and we are ready to start running examples in it.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-3-sql-basics\"><a name=\"sql_basics\"><\/a>3. SQL Basics<\/h2>\n<p>Before we dive into the SQL Data Types let&#8217;s see some basics for SQL. SQL stands for Structured Query Language and allows you to do <strong>CRUD<\/strong> (Create, Read, Update, Delete) operations on database <strong>tables<\/strong>. A table is a collection of data and is made up of <strong>rows<\/strong> and <strong>columns<\/strong>. The rows are used to store data and the columns hold the data type. In this post, we will focus on the data types which are essentially the column part of a table. Each table must have a unique identifier for the rows, also called the <strong>primary key<\/strong>.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-creating-a-table\">Creating a table<\/h4>\n<p>Let&#8217;s now create the table that we will use in the examples below. The table simply represents the <em>articles<\/em> of a blog. In the MySQL Command-Line Client run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Create a test table<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; CREATE TABLE articles (\n    id INT AUTO_INCREMENT,\n    title VARCHAR(64) NOT NULL,\n    posted_by VARCHAR(64) NOT NULL,\n    posted_date DATE,\n    active BIT(1) NOT NULL,\n    last_update_date DATETIME,\n    rating_percentage DOUBLE,\n    views BIGINT,\n    no_of_comments SMALLINT,\n    category ENUM('JAVA', 'QUARTZ'),\n    body TEXT,\n    metadata JSON,\n    PRIMARY KEY (id)\n);\n<\/pre>\n<p>In the table above, the <strong>id<\/strong> is the primary key which auto increments during an insert. We will examine the rest of the columns in the following section.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-view-the-table-structure\">View the table structure<\/h4>\n<p>To view the structure of the <em>articles<\/em> table we just created, run the following command:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Show articles table structure<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; describe articles;\n+-------------------+-----------------------+------+-----+---------+----------------+\n| Field             | Type                  | Null | Key | Default | Extra          |\n+-------------------+-----------------------+------+-----+---------+----------------+\n| id                | int(11)               | NO   | PRI | NULL    | auto_increment |\n| title             | varchar(64)           | NO   |     | NULL    |                |\n| posted_by         | varchar(64)           | NO   |     | NULL    |                |\n| posted_date       | date                  | YES  |     | NULL    |                |\n| active            | bit(1)                | NO   |     | NULL    |                |\n| last_update_date  | datetime              | YES  |     | NULL    |                |\n| rating_percentage | double                | YES  |     | NULL    |                |\n| views             | bigint(20)            | YES  |     | NULL    |                |\n| no_of_comments    | smallint(6)           | YES  |     | NULL    |                |\n| category          | enum('JAVA','QUARTZ') | YES  |     | NULL    |                |\n| body              | text                  | YES  |     | NULL    |                |\n| metadata          | json                  | YES  |     | NULL    |                |\n+-------------------+-----------------------+------+-----+---------+----------------+\n<\/pre>\n<p>This command is very useful when we want to view the data type for a table.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h4 class=\"wp-block-heading\" id=\"h-inserting-test-data-into-table\">Inserting test data into table<\/h4>\n<p>Finally, we have to insert some articles into the table we created in the previous section. Open the MySQL Command-Line Client and run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Insert data into articles table<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; insert into articles(title, posted_by, posted_date, active, last_update_date, rating_percentage, views, no_of_comments, category, body, metadata) values \n('Java Microservices', 'bob', '2019-04-01', 1, '2019-03-29 05:10:23', 85.23, 453, 5, 'JAVA', 'blah', '{\"total_author_posts\": 15, \"tags\": [\"Java\", \"Microservices\"]}'),\n('Quartz Best Practices', 'tom', '2018-11-05', 1, '2018-11-04 15:43:00', 76.3, 7834, 28, 'QUARTZ', 'blah', '{\"total_author_posts\": 4, \"tags\": [\"Quartz\"]}'),\n('Java HashMap', 'tom', '2015-04-24', 0, '2015-04-20', 34, 6543, 2, 'JAVA', 'blah', '{\"tags\": [\"Java\"]}');\n<\/pre>\n<p>We added three rows to the test table. Notice that we didn&#8217;t add any value in the <strong>id<\/strong> column, as it auto increments as we said before. To confirm that run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>View articles data<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; select id, title from articles;\n+----+-----------------------+\n| id | title                 |\n+----+-----------------------+\n|  1 | Java Microservices    |\n|  2 | Quartz Best Practices |\n|  3 | Java HashMap          |\n+----+-----------------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>That returns 3 rows that have an auto-incremented id. We have finished creating a test table and insert some test data into it. In the following section, we will see the SQL Data Types and use the table we created in our examples.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-sql-data-types\"><a name=\"sql_data_types\"><\/a>4. SQL Data Types<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"606\" height=\"403\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/sql-data-types.jpg\" alt=\"SQL Data Types\" class=\"wp-image-71295\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/sql-data-types.jpg 606w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/sql-data-types-300x200.jpg 300w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><figcaption>SQL Data Types<\/figcaption><\/figure>\n<\/div>\n<p>Like any programming language, SQL also has many data types. If we could divide the SQL data types into categories then those would be:<\/p>\n<ul class=\"wp-block-list\">\n<li>Numeric<\/li>\n<li>Character<\/li>\n<li>Date and Time<\/li>\n<li>JSON \/ XML<\/li>\n<\/ul>\n<p>Each relational database does not have support for all the data types that we will see in the following sections. We will examine the most widely used ones and focus on the equivalent data types of MySQL in the code examples.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-1-numeric\"><a name=\"numeric_data_types\" class=\"mce-item-anchor\"><\/a>4.1 Numeric<\/h3>\n<p>The numeric data types hold numbers with or without scale and are divided into 4 main categories:<\/p>\n<ul class=\"wp-block-list\">\n<li>BIT<\/li>\n<li>INTEGER<\/li>\n<li>FIXED POINT<\/li>\n<li>FLOATING POINT<\/li>\n<\/ul>\n<p>Let&#8217;s see in more detail each one of those in the following sections.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-bit\">BIT<\/h4>\n<p>The <strong>BIT(M)<\/strong> data type stores bit values. It usually ranges from 0-1 but in MySQL, it ranges from 1-64. The <strong>BIT(1)<\/strong> can also act as a boolean (true or false).<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-integer\">INTEGER<\/h4>\n<p>There are various integer data types that should be used depending on the range needed for each use case. The following table shows all the integer data types and their range and required storage.<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td><strong>DATA TYPE<\/strong><\/td>\n<td><strong>RANGE FROM<\/strong><\/td>\n<td><strong>RANGE TO<\/strong><\/td>\n<td><strong>STORAGE<\/strong><\/td>\n<\/tr>\n<tr>\n<td>TINYINT<\/td>\n<td>0<\/td>\n<td>255<\/td>\n<td>1 Byte<\/td>\n<\/tr>\n<tr>\n<td>SMALLINT<\/td>\n<td>-32,768<\/td>\n<td>32,767<\/td>\n<td>2 Bytes<\/td>\n<\/tr>\n<tr>\n<td>MEDIUMINT<\/td>\n<td>-8,388,608<\/td>\n<td>8,388,608<\/td>\n<td>3 Bytes<\/td>\n<\/tr>\n<tr>\n<td>INT<\/td>\n<td>-2,147,483,648<\/td>\n<td>2,147,483,648<\/td>\n<td>4 Bytes<\/td>\n<\/tr>\n<tr>\n<td>BIGINT<\/td>\n<td>-9,223,372,036,854,775,808<\/td>\n<td>9,223,372,036,854,775,808<\/td>\n<td>8 Bytes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h4 class=\"wp-block-heading\" id=\"h-fixed-point\">FIXED POINT<\/h4>\n<p>The <strong>DECIMAL(M, D)<\/strong> is a fixed-point data type that has fixed precision and scale. <em><code>M<\/code><\/em>\u00a0is the total number of digits (the precision) and\u00a0<em><code>D<\/code><\/em> is the number of digits after the decimal point (the scale). In MySQL, the maximum number of digits (<em><code>M<\/code><\/em>) for DECIMAL is 65 and the maximum number of supported decimals (<em><code>D<\/code><\/em>) is 30.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-floating-point\">FLOATING POINT<\/h4>\n<p>The floating-point data types are the <strong>DOUBLE(M, D)<\/strong> and <strong>FLOAT(M, D)<\/strong>. The DOUBLE is a small (single-precision) floating-point number, whereas the FLOAT is a normal-size (double-precision) floating-point number. The following table shows the ranges and required storage for those data types:<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td><strong>DATA TYPE<\/strong><\/td>\n<td><strong>RANGE FROM<\/strong><\/td>\n<td><strong>RANGE TO<\/strong><\/td>\n<td><strong>STORAGE<\/strong><\/td>\n<\/tr>\n<tr>\n<td>FLOAT<\/td>\n<td>-3.402823466E+38<\/td>\n<td>3.402823466E+38<\/td>\n<td>4 Bytes<\/td>\n<\/tr>\n<tr>\n<td>DOUBLE<\/td>\n<td>-1.7976931348623157E+308<\/td>\n<td>1.7976931348623157E+308<\/td>\n<td>8 Bytes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3 class=\"wp-block-heading\" id=\"h-example\">Example<\/h3>\n<p>Let&#8217;s go back to our <em>articles<\/em> table we created before and examine the numeric columns of it:<\/p>\n<ul class=\"wp-block-list\">\n<li>id INT<\/li>\n<li>active BIT(1)<\/li>\n<li>rating_percentage DOUBLE<\/li>\n<li>views BIGINT<\/li>\n<li>no_of_comments SMALLINT<\/li>\n<\/ul>\n<p>The <em>id<\/em> is the primary key and is of type INT. Note that if we had too many records into this table then having declared that as INT would not be sufficient. The <em>active<\/em> column is a BIT(1) which acts as a boolean. The <em>rating_percentage<\/em> is a DOUBLE and takes values with precision. The <em>view<\/em> is BIGINT as we might reach a huge number of viewers. Finally, the <em>no_of_comments<\/em> is a SMALLINT as we might need to limit the comments for our articles.<\/p>\n<p>To view all those columns open the MySQL Command-Line Client and run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>View numeric columns<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; select id, active+0, rating_percentage, views, no_of_comments from articles;\n+----+----------+-------------------+-------+----------------+\n| id | active+0 | rating_percentage | views | no_of_comments |\n+----+----------+-------------------+-------+----------------+\n|  1 |        1 |             85.23 |   453 |              5 |\n|  2 |        1 |              76.3 |  7834 |             28 |\n|  3 |        0 |                34 |  6543 |              2 |\n+----+----------+-------------------+-------+----------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>This query returns all the numeric columns of our articles table. Note the <em>active+0<\/em> we used here. This is because the BIT is stored as a binary in MySQL so we have to convert it to text in order to view it properly.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-2-character\"><a name=\"character_data_types\" class=\"mce-item-anchor\"><\/a>4.2 Character<\/h3>\n<p>The Character data type is a synonym for the String data type. Each character data type can be stored as a string or binary and has an equivalent Unicode data type. The following table shows a list of Character data types:<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td> <strong>DATA TYPE<\/strong><\/td>\n<td><strong>UNICODE DATA TYPE<\/strong><\/td>\n<td>BINARY<\/td>\n<td><strong>STORAGE<\/strong><\/td>\n<\/tr>\n<tr>\n<td>CHAR<\/td>\n<td>NCHAR<\/td>\n<td>BINARY<\/td>\n<td>Fixed-length &#8211; uses the same amount of storage space per entry<\/td>\n<\/tr>\n<tr>\n<td>VARCHAR<\/td>\n<td>NVARCHAR<\/td>\n<td>VARBINARY<\/td>\n<td>Variable-length &#8211; uses the amount necessary to store the actual text<\/td>\n<\/tr>\n<tr>\n<td>TEXT<\/td>\n<td>NTEXT<\/td>\n<td>BLOB<\/td>\n<td>Variable-huge-length &#8211; uses the amount necessary to store the actual text<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h4 class=\"wp-block-heading\" id=\"h-char-nchar-binary\">CHAR &#8211; NCHAR &#8211; BINARY<\/h4>\n<p>The length of the <strong>CHAR<\/strong> is fixed to the length that you declare when you create the table. In MySQL, the length can be any value from 0 to 255. The <strong>NCHAR<\/strong> is the Unicode version of CHAR and the <strong>BINARY<\/strong> is the binary version of it.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-varchar-nvarchar-varbinary\">VARCHAR &#8211; NVARCHAR &#8211; VARBINARY<\/h4>\n<p>Values in the <strong>VARCHAR<\/strong> are variable-length strings. In MySQL, the length can be specified as a value from 0 to 65,535. The <strong>NVARCHAR<\/strong> is the Unicode version of VARCHAR and the <strong>VARBINARY<\/strong> is the binary version of it. <\/p>\n<h4 class=\"wp-block-heading\" id=\"h-text-ntext-blob\">TEXT &#8211; NTEXT &#8211; BLOB<\/h4>\n<p>The <strong>TEXT<\/strong> is a variable-length string that stores huge strings in a non-binary format. The NTEXT is the Unicode version of TEXT and the <span><b>BLOB<\/b> <\/span>is the binary version of it.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-enum\">ENUM<\/h4>\n<p>Another character data type is the <strong>ENUM<\/strong>. The ENUM is a list of string values that are defined during the table creation. You can&#8217;t set an ENUM to a value that is not defined in the list.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-example-1\">Example<\/h3>\n<p>Let&#8217;s go back to our <em>articles<\/em> table we created before and examine the character columns of it:<\/p>\n<ul class=\"wp-block-list\">\n<li>title VARCHAR(64)<\/li>\n<li>posted_by VARCHAR(64)<\/li>\n<li>body TEXT<\/li>\n<li>category ENUM(&#8216;JAVA&#8217;, &#8216;QUARTZ&#8217;)<\/li>\n<\/ul>\n<p>The <em>title<\/em> and <em>posted_by<\/em> are VARCHAR with a maximum length of 64 characters. The <em>body<\/em> is the actual article body and should be a huge string that&#8217;s why it&#8217;s declared a TEXT. The <em>category<\/em> is an ENUM which can take only 2 values, JAVA or QUARTZ.<\/p>\n<p>To view all those columns open the MySQL Command-Line Client and run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>View character columns<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; select id, title, posted_by, category, body from articles;\n+----+-----------------------+-----------+----------+------+\n| id | title                 | posted_by | category | body |\n+----+-----------------------+-----------+----------+------+\n|  1 | Java Microservices    | bob       | JAVA     | blah |\n|  2 | Quartz Best Practices | tom       | QUARTZ   | blah |\n|  3 | Java HashMap          | tom       | JAVA     | blah |\n+----+-----------------------+-----------+----------+------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>The result set shows all the character columns. Note here that the <em>body<\/em> column is shown as a string and not as a binary.<\/p>\n<p>Let&#8217;s try to change the <em>category<\/em> value of the first row to a value that is not defined in the ENUM and see the error we&#8217;ll get: <\/p>\n<p><span style=\"text-decoration: underline\"><em>Change the value of ENUM<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; update articles set category = 'Microservices' where id = 1;\nERROR 1265 (01000): Data truncated for column 'category' at row 1\n<\/pre>\n<p>As we see MySQL returns an error when we try to set the value of an ENUM data type to a non defined value.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-3-date-and-time\"><a name=\"data_time_data_types\" class=\"mce-item-anchor\"><\/a>4.3 Date and Time<\/h3>\n<p>The <strong>DATE<\/strong> and <strong>TIME<\/strong> data types are very important when it comes to saving dates and times. The following table shows the different date and time data types:<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td><strong>DATA TYPE<\/strong><\/td>\n<td><strong>FORMAT<\/strong><\/td>\n<\/tr>\n<tr>\n<td>DATE<\/td>\n<td>YYYY-MM-DD<\/td>\n<\/tr>\n<tr>\n<td>DATETIME<\/td>\n<td>YYYY-MM-DD HH:MI:SS<\/td>\n<\/tr>\n<tr>\n<td>TIME<\/td>\n<td>HH:MI:SS<\/td>\n<\/tr>\n<tr>\n<td>YEAR<\/td>\n<td>YYYY<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h4 class=\"wp-block-heading\" id=\"h-date\">DATE<\/h4>\n<p>The <strong>DATE<\/strong> stores year, month and day in YYYY-MM-DD format.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-datetime\">DATETIME<\/h4>\n<p>The <strong>DATETIME<\/strong> stores year, month, day, hour, minute and second in YYYY-MM-DD HH:MI:SS format.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-time\">TIME<\/h4>\n<p>The <strong>TIME<\/strong> stores hour, minute and second in HH:MI:SS format.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-year\">YEAR<\/h4>\n<p>The <strong>YEAR<\/strong> stores year in 2-digit (YY) or 4-digit (YYYY) format.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-example-2\">Example<\/h3>\n<p>Let\u2019s go back to our&nbsp;<em>articles<\/em> table we created before and examine the date and time columns of it:<\/p>\n<ul class=\"wp-block-list\">\n<li>posted_date DATE<\/li>\n<li>last_update_date DATETIME<\/li>\n<\/ul>\n<p>The <em>posted_date<\/em> is a DATE as we are not interested in the time of the posted date. The <em>last_update_date<\/em> is a DATETIME as it shows the exact date and time the article was updated.<\/p>\n<p>To view all those columns open the MySQL Command-Line Client and run:<\/p>\n<p><span style=\"text-decoration: underline\"><em>View date and time columns<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; select id, posted_date, last_update_date from articles;\n+----+-------------+---------------------+\n| id | posted_date | last_update_date    |\n+----+-------------+---------------------+\n|  1 | 2019-04-01  | 2019-03-29 05:10:23 |\n|  2 | 2018-11-05  | 2018-11-04 15:43:00 |\n|  3 | 2015-04-24  | 2015-04-20 00:00:00 |\n+----+-------------+---------------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>The result set returns the 3 rows with the date and time columns. Note that the <em>last_update_date<\/em> of the third row didn&#8217;t have time when we inserted it, but MySQL formats that column with time and returns 00:00:00.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-4-json-xml\"><a name=\"json_xml_data_types\" class=\"mce-item-anchor\"><\/a>4.4 JSON \/ XML<\/h3>\n<p>The <strong>JSON<\/strong> and <strong>XML<\/strong> are special SQL data types that store <a aria-label=\"JSON (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/JSON\" target=\"_blank\">JSON<\/a> or <a aria-label=\"XML (opens in a new tab)\" rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/XML\" target=\"_blank\">XML<\/a> documents respectively. The JSON data type provides automatic validation of JSON documents and optimized storage format. You can validate a JSON before inserting it <a aria-label=\"here (opens in a new tab)\" href=\"https:\/\/jsonlint.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. The XML data type is not supported by MySQL but you can use a TEXT data type to store XML.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-example-3\">Example<\/h3>\n<p>Let\u2019s go back to our <em>articles<\/em> table we created before and examine the JSON column of it: <\/p>\n<p><span style=\"text-decoration: underline\"><em>View JSON column<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; select id, title, metadata from articles;\n+----+-----------------------+---------------------------------------------------------------+\n| id | title                 | metadata                                                      |\n+----+-----------------------+---------------------------------------------------------------+\n|  1 | Java Microservices    | {\"tags\": [\"Java\", \"Microservices\"], \"total_author_posts\": 15} |\n|  2 | Quartz Best Practices | {\"tags\": [\"Quartz\"], \"total_author_posts\": 4}                 |\n|  3 | Java HashMap          | {\"tags\": [\"Java\"]}                                            |\n+----+-----------------------+---------------------------------------------------------------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>The above JSON values are valid, otherwise, they wouldn&#8217;t be inserted. Let&#8217;s try and update the <em>metadata<\/em> column with an invalid JSON and see what will happen:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Update JSON to invalid one<\/em><\/span><\/p>\n<pre class=\"brush:bash\">mysql&gt; update articles set metadata = '{\"tags: Java\"}' where id = 1;\nERROR 3140 (22032): Invalid JSON text: \"Missing a colon after a name of object member.\" at position 14 in value for column 'articles.metadata'.\n<\/pre>\n<p>As we see, MySQL does not allow us to insert an invalid JSON in a JSON column and returns an error.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-sql-data-types-best-practices\"><a name=\"best_practices\"><\/a>5. SQL Data Types &#8211; Best Practices<\/h2>\n<p>In this section, we will explore best practices for choosing the appropriate SQL Data Type. By doing that you will get better performance of disk, memory and CPU. Let&#8217;s see below some of those best practices.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-choose-the-smallest-data-type\">Choose the smallest data type<\/h4>\n<p>Make sure you always choose the smallest data type for a table column. That will be beneficial due to less space on the disk, in memory, and in the CPU cache. If you are in doubt as to which data type is the smallest for your use case, then always choose the smallest that you are sure you won&#8217;t exceed. You can always change the data type, but you should avoid doing that as it is a time-consuming operation. For example, in the <em>articles<\/em> table, we used the SMALINT data type for the <em>no_of_comments<\/em> columns as we assumed that we wouldn&#8217;t have more than 32,767 comments for an article.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-choose-the-simplest-data-type\">Choose the simplest data type<\/h4>\n<p>Always choose the simplest SQL data type. By that, we mean that integer is cheaper to compare than character and date and time are better than storing a DateTime as a character. This will lower the CPU required for operations such as comparing or sorting.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-avoid-null-data-type-values\">Avoid NULL data type values<\/h4>\n<p>Many developers choose to make a table column NULL, as they are not 100% sure if it can take a non-null value during an insert. It\u2019s harder for a database engine to optimize queries that refer to NULL columns, because they make indexes and comparisons more complicated, use more storage space and require special processing.<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-avoid-using-enum\">Avoid using ENUM<\/h4>\n<p>At first glance, ENUM seems to be a great data type to use, as it has a predefined list it can take values from and as such it&#8217;s easy for developers to know beforehand which value to use. However, there will be times that you would want to add new values to the ENUM list. That is because, when adding a new ENUM value the database will have to rebuild the entire table which might take a lot of time and will slow the overall performance of the database.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-6-conclusion\"><a name=\"conclusion\"><\/a>6. Conclusion<\/h2>\n<p>In this post, we examined the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also created a test database and table using the open-source MySQL database and provided several code examples. Finally, we covered best practices for choosing the right SQL Data Type to improve the performance of a database.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-7-download-the-sql-commands\"><a name=\"download_sql\"><\/a>7. Download the SQL commands<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the SQL commands of the above examples here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/05\/SQLDataTypesTutorial.sql_.zip\"><strong>SQL Data Types Tutorial<\/strong><\/a><\/div>\n<p><strong>Last updated on Nov. 07th, 2021<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction SQL is the language used to communicate with Relational Databases such as MySQL, Oracle, MS SQL Server, PostgreSQL, etc. In this post, we will examine the various SQL Data Types and provide examples for MySQL, which is the most widely used open-source database. This post requires some knowledge in SQL and a tutorial &hellip;<\/p>\n","protected":false},"author":172,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[1055],"class_list":["post-71096","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Data Types Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Data Types Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/lefteris.karageorgiou.5\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-13T08:00:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-07T21:29:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Lefteris Karageorgiou\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lefkos77\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lefteris Karageorgiou\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\"},\"author\":{\"name\":\"Lefteris Karageorgiou\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/777c6779bb34786b415482271b84c5bb\"},\"headline\":\"SQL Data Types Tutorial\",\"datePublished\":\"2019-05-13T08:00:22+00:00\",\"dateModified\":\"2021-11-07T21:29:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\"},\"wordCount\":2488,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"sql\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\",\"name\":\"SQL Data Types Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2019-05-13T08:00:22+00:00\",\"dateModified\":\"2021-11-07T21:29:37+00:00\",\"description\":\"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL Data Types Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/777c6779bb34786b415482271b84c5bb\",\"name\":\"Lefteris Karageorgiou\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7c6f5f16615b972cea90bb51c2a673d4bfd52036ade7ca8936069dd8fd1a46ad?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7c6f5f16615b972cea90bb51c2a673d4bfd52036ade7ca8936069dd8fd1a46ad?s=96&d=mm&r=g\",\"caption\":\"Lefteris Karageorgiou\"},\"description\":\"Lefteris is a Lead Software Engineer at ZuluTrade and has been responsible for re-architecting the backend of the main website from a monolith to event-driven microservices using Java, Spring Boot\/Cloud, RabbitMQ, Redis. He has extensive work experience for over 10 years in Software Development, working mainly in the FinTech and Sports Betting industries. Prior to joining ZuluTrade, Lefteris worked as a Senior Java Developer at Inspired Gaming Group in London, building enterprise sports betting applications for William Hills and Paddy Power. He enjoys working with large-scalable, real-time and high-volume systems deployed into AWS and wants to combine his passion for technology and traveling by attending software conferences all over the world.\",\"sameAs\":[\"https:\/\/www.facebook.com\/lefteris.karageorgiou.5\",\"https:\/\/www.linkedin.com\/in\/lefteris-karageorgiou-ba1ab926\/\",\"https:\/\/x.com\/lefkos77\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/lefteris-karageorgiou\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Data Types Tutorial - Java Code Geeks","description":"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"SQL Data Types Tutorial - Java Code Geeks","og_description":"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.","og_url":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/lefteris.karageorgiou.5","article_published_time":"2019-05-13T08:00:22+00:00","article_modified_time":"2021-11-07T21:29:37+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Lefteris Karageorgiou","twitter_card":"summary_large_image","twitter_creator":"@lefkos77","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Lefteris Karageorgiou","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/"},"author":{"name":"Lefteris Karageorgiou","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/777c6779bb34786b415482271b84c5bb"},"headline":"SQL Data Types Tutorial","datePublished":"2019-05-13T08:00:22+00:00","dateModified":"2021-11-07T21:29:37+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/"},"wordCount":2488,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["sql"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/","name":"SQL Data Types Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2019-05-13T08:00:22+00:00","dateModified":"2021-11-07T21:29:37+00:00","description":"In this post, we examine the various SQL Data Types: Numeric, Character, Date and Time, JSON \/ XML. We also create a test database and table.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-data-types-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL Data Types Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/777c6779bb34786b415482271b84c5bb","name":"Lefteris Karageorgiou","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7c6f5f16615b972cea90bb51c2a673d4bfd52036ade7ca8936069dd8fd1a46ad?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7c6f5f16615b972cea90bb51c2a673d4bfd52036ade7ca8936069dd8fd1a46ad?s=96&d=mm&r=g","caption":"Lefteris Karageorgiou"},"description":"Lefteris is a Lead Software Engineer at ZuluTrade and has been responsible for re-architecting the backend of the main website from a monolith to event-driven microservices using Java, Spring Boot\/Cloud, RabbitMQ, Redis. He has extensive work experience for over 10 years in Software Development, working mainly in the FinTech and Sports Betting industries. Prior to joining ZuluTrade, Lefteris worked as a Senior Java Developer at Inspired Gaming Group in London, building enterprise sports betting applications for William Hills and Paddy Power. He enjoys working with large-scalable, real-time and high-volume systems deployed into AWS and wants to combine his passion for technology and traveling by attending software conferences all over the world.","sameAs":["https:\/\/www.facebook.com\/lefteris.karageorgiou.5","https:\/\/www.linkedin.com\/in\/lefteris-karageorgiou-ba1ab926\/","https:\/\/x.com\/lefkos77"],"url":"https:\/\/examples.javacodegeeks.com\/author\/lefteris-karageorgiou\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/71096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/172"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=71096"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/71096\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=71096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=71096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=71096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}