{"id":1296,"date":"2018-01-17T06:31:46","date_gmt":"2018-01-17T13:31:46","guid":{"rendered":"https:\/\/sqltutorial.org\/?page_id=1296"},"modified":"2026-04-01T02:21:53","modified_gmt":"2026-04-01T09:21:53","slug":"sql-data-types","status":"publish","type":"page","link":"https:\/\/www.sqltutorial.org\/sql-data-types\/","title":{"rendered":"SQL Data Types"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"alignright\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"116\" src=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types-300x116.png\" alt=\"SQL Data Types\" class=\"wp-image-1299\" title=\"SQL Data Types\" srcset=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types-300x116.png 300w, https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png 736w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/figure>\n<\/div>\n\n\n<p><strong>Summary<\/strong>: In this tutorial, you&#8217;ll learn the most common SQL data types, including string, numeric, and date and time types, and when to use each one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='what-are-sql-data-types'>What are SQL data types? <a href=\"#what-are-sql-data-types\" class=\"anchor\" id=\"what-are-sql-data-types\" title=\"Anchor for What are SQL data types?\">#<\/a><\/h2>\n\n\n\n<p>In a database, every column of a table has a specific data type. A data type specifies the type of values that a column can store, such as strings, numbers, and dates.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first name column stores strings.<\/li>\n\n\n\n<li>The salary column stores numbers.<\/li>\n\n\n\n<li>The date of birth column stores date values.<\/li>\n\n\n\n<li>The created-at column stores both date and time.<\/li>\n<\/ul>\n\n\n\n<p>When designing tables, you should choose the right SQL data type because it affects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The kind of data a column can store<\/li>\n\n\n\n<li>Storage<\/li>\n\n\n\n<li>Data validation &amp; accuracy<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='most-common-sql-data-types'>Most Common SQL Data Types <a href=\"#most-common-sql-data-types\" class=\"anchor\" id=\"most-common-sql-data-types\" title=\"Anchor for Most Common SQL Data Types\">#<\/a><\/h2>\n\n\n\n<p>SQL organizes the data into the following main groups:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='string-data-types'>String data types <a href=\"#string-data-types\" class=\"anchor\" id=\"string-data-types\" title=\"Anchor for String data types\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>CHAR<\/code><\/li>\n\n\n\n<li><code>VARCHAR<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='numeric-data-types'>Numeric data types <a href=\"#numeric-data-types\" class=\"anchor\" id=\"numeric-data-types\" title=\"Anchor for Numeric data types\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>INT<\/code><\/li>\n\n\n\n<li><code>SMALLINT<\/code><\/li>\n\n\n\n<li><code>BIGINT<\/code><\/li>\n\n\n\n<li><code>DECIMAL<\/code><\/li>\n\n\n\n<li><code>FLOAT<\/code><\/li>\n\n\n\n<li><code>REAL<\/code><\/li>\n\n\n\n<li><code>DOUBLE PRECISION<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='data-and-time-data-types'>Data and time data types <a href=\"#data-and-time-data-types\" class=\"anchor\" id=\"data-and-time-data-types\" title=\"Anchor for Data and time data types\">#<\/a><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>DATE<\/code><\/li>\n\n\n\n<li><code>TIME<\/code><\/li>\n\n\n\n<li><code>TIMESTAMP<\/code><\/li>\n<\/ul>\n\n\n\n<p>Note that the exact syntax may vary slightly depending on the database system, such as <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-data-types\/\">MySQL<\/a>, <a href=\"https:\/\/www.pgtutorial.com\/#postgresql-data-types\">PostgreSQL<\/a>, <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-data-types\/\">SQL Server<\/a>, or <a href=\"https:\/\/www.oracletutorial.com\/oracle-basics\/oracle-data-types\/\">Oracle<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-string-data-types'>SQL String Data Types <a href=\"#sql-string-data-types\" class=\"anchor\" id=\"sql-string-data-types\" title=\"Anchor for SQL String Data Types\">#<\/a><\/h2>\n\n\n\n<p>String data types store text values such as names, job titles, and department names.<\/p>\n\n\n\n<p>SQL has the following common string data types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>CHAR<\/code><\/li>\n\n\n\n<li><code>VARCHAR<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='char'>CHAR <a href=\"#char\" class=\"anchor\" id=\"char\" title=\"Anchor for CHAR\">#<\/a><\/h3>\n\n\n\n<p><code>CHAR<\/code> stores a <strong>fixed-length<\/strong> string.<\/p>\n\n\n\n<p>Here&#8217;s the syntax<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CHAR (n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax, <code>n<\/code> is a fixed number of characters that the column stores. The <code>n<\/code> parameter is optional. If you skip it, the database uses <code>1<\/code> by default.<\/p>\n\n\n\n<p>So the following declaration:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CHAR<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>is equivalent to the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CHAR (1)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The maximum value of <code>n<\/code> depends on the specific implementation of the database system.<\/p>\n\n\n\n<p>Note that <code>CHAR<\/code> and <code>CHARACTER<\/code> are equivalent:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">CHARACTER(n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following defines a column with the fixed-length character data type, which can store up to five characters:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">column_name CHARACTER(5)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you store a string whose length is two in the column above, then the database system will pad the three spaces to the string to ensure that each value in a column has a fixed length of five.<\/p>\n\n\n\n<p>An example of using the fixed-length character data type is to store state abbreviations because all state abbreviations are two characters, e.g., <code>CA<\/code>, <code>NY<\/code>, and <code>TX<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-char'>When to use CHAR <a href=\"#when-to-use-char\" class=\"anchor\" id=\"when-to-use-char\" title=\"Anchor for When to use CHAR\">#<\/a><\/h3>\n\n\n\n<p>Use <code>CHAR<\/code> for fixed-length values such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Country codes like US, FR, DE<\/li>\n\n\n\n<li>State abbreviations like CA, TX<\/li>\n\n\n\n<li>Fixed-length status flags<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='varchar'>VARCHAR <a href=\"#varchar\" class=\"anchor\" id=\"varchar\" title=\"Anchor for VARCHAR\">#<\/a><\/h3>\n\n\n\n<p><code>VARCHAR<\/code> stores varying-length strings. <\/p>\n\n\n\n<p>Here&#8217;s the syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">VARCHAR(n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax, n represents the maximum number of characters that the column can store. Some database systems allow you to specify the number of bytes that the column can store.<\/p>\n\n\n\n<p>The following example defines a column with the <code>VARCHAR<\/code> data type:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">first_name VARCHAR(50)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you store a value whose length is 20 in the <code>first_name<\/code> column, the database stores that value without padding it to the full length.<\/p>\n\n\n\n<p>However, if you store a value with a length greater than 50, the database may issue an error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-varchar'>When to use VARCHAR <a href=\"#when-to-use-varchar\" class=\"anchor\" id=\"when-to-use-varchar\" title=\"Anchor for When to use VARCHAR\">#<\/a><\/h3>\n\n\n\n<p>In practice, you use <code>VARCHAR<\/code> when the string length varies, for example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>first names<\/li>\n\n\n\n<li>email addresses<\/li>\n\n\n\n<li>product names<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='char-vs-varchar'>CHAR vs VARCHAR <a href=\"#char-vs-varchar\" class=\"anchor\" id=\"char-vs-varchar\" title=\"Anchor for CHAR vs VARCHAR\">#<\/a><\/h3>\n\n\n\n<p>When you start learning SQL data types, you often find difficulty in choosing between <code>CHAR<\/code> and <code>VARCHAR<\/code>. Here are some tips:<\/p>\n\n\n\n<p>Use <code>CHAR<\/code> when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The value length is fixed.<\/li>\n\n\n\n<li>All values have the same length.<\/li>\n<\/ul>\n\n\n\n<p>Use <code>VARCHAR<\/code> when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The value length varies<\/li>\n\n\n\n<li>All values do not have the same length.<\/li>\n<\/ul>\n\n\n\n<p>In practice, <code>VARCHAR<\/code> is more common than <code>CHAR<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-numeric-data-types'>SQL Numeric Data Types <a href=\"#sql-numeric-data-types\" class=\"anchor\" id=\"sql-numeric-data-types\" title=\"Anchor for SQL Numeric Data Types\">#<\/a><\/h2>\n\n\n\n<p>Numeric data type stores numbers such as age and salary.<\/p>\n\n\n\n<p>Here are the most common SQL numeric data types: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SMALLINT<\/code><\/li>\n\n\n\n<li><code>INT<\/code><\/li>\n\n\n\n<li><code>BIGINT<\/code><\/li>\n\n\n\n<li><code>DECIMAL<\/code><\/li>\n\n\n\n<li><code>NUMERIC<\/code><\/li>\n\n\n\n<li><code>FLOAT<\/code><\/li>\n\n\n\n<li><code>REAL<\/code><\/li>\n\n\n\n<li><code>DOUBLE PRECISION<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='decimal-and-numeric'>DECIMAL and NUMERIC <a href=\"#decimal-and-numeric\" class=\"anchor\" id=\"decimal-and-numeric\" title=\"Anchor for DECIMAL and NUMERIC\">#<\/a><\/h3>\n\n\n\n<p>The <code>DECIMAL<\/code> and <code>NUMERIC<\/code> data type stores exact numeric values. Typically, you use these types for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Salaries<\/li>\n\n\n\n<li>Prices<\/li>\n\n\n\n<li>and any number where precision matters<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s the syntax for defining a column with the <code>DECIMAL<\/code> data type:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">column_name DECIMAL (p,s)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>p is the <strong>precision<\/strong>, or total number of digits.<\/li>\n\n\n\n<li>s is the <strong>scale<\/strong>, or number of digits after the decimal point.<\/li>\n<\/ul>\n\n\n\n<p>The maximum values of <code>p<\/code> and <code>s<\/code> depend on the implementation of each database system.<\/p>\n\n\n\n<p>The following defines the salary column with 12 digits, which includes 4 digits after the decimal point:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">salary DECIMAL (12,4)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The salary column can store a number with a value up to <code>99,999,999.9999<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-decimal'>When to use DECIMAL <a href=\"#when-to-use-decimal\" class=\"anchor\" id=\"when-to-use-decimal\" title=\"Anchor for When to use DECIMAL\">#<\/a><\/h3>\n\n\n\n<p>In practice, you use <code>DECIMAL<\/code> to store values that must be exact, especially for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Money<\/li>\n\n\n\n<li>Financial calculations<\/li>\n\n\n\n<li>Measurement<br><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='integer-types'>Integer types <a href=\"#integer-types\" class=\"anchor\" id=\"integer-types\" title=\"Anchor for Integer types\">#<\/a><\/h3>\n\n\n\n<p>Integer types store whole numbers, without decimal places. <\/p>\n\n\n\n<p>Here are common integer types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SMALLINT<\/code> &#8211; smaller whole numbers.<\/li>\n\n\n\n<li><code>INT<\/code> or <code>INTEGER<\/code> &#8211; standard whole numbers.<\/li>\n\n\n\n<li><code>BIGINT<\/code> &#8211; very big whole numbers.<\/li>\n<\/ul>\n\n\n\n<p>Here&#8217;s an example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">employee_id INT<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-integer-types'>When to use integer types <a href=\"#when-to-use-integer-types\" class=\"anchor\" id=\"when-to-use-integer-types\" title=\"Anchor for When to use integer types\">#<\/a><\/h3>\n\n\n\n<p>In practice, you use integer types for values such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ID<\/li>\n\n\n\n<li>Ages<\/li>\n\n\n\n<li>Ranking<\/li>\n\n\n\n<li>Quantities<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='floating-point-data-types'>Floating-point data types <a href=\"#floating-point-data-types\" class=\"anchor\" id=\"floating-point-data-types\" title=\"Anchor for Floating-point data types\">#<\/a><\/h2>\n\n\n\n<p>The floating-point data types represent approximate numeric values.  <\/p>\n\n\n\n<p>Here are common floating-point types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>FLOAT<\/code><\/li>\n\n\n\n<li><code>REAL<\/code><\/li>\n\n\n\n<li><code>DOUBLE PRECISION<\/code><\/li>\n<\/ul>\n\n\n\n<p>You use Floating-point data types for values where a small rounding difference is acceptable. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">temperature FLOAT<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you store money values, you should use <code>DECIMAL<\/code> instead of <code>FLOAT<\/code> because <code>FLOAT<\/code> stores approximate values that can cause rounding differences.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='decimal-vs-float'>DECIMAL vs FLOAT <a href=\"#decimal-vs-float\" class=\"anchor\" id=\"decimal-vs-float\" title=\"Anchor for DECIMAL vs FLOAT\">#<\/a><\/h3>\n\n\n\n<p>Use <code>DECIMAL<\/code> to store exact values and <code>FLOAT<\/code> to store approximate values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='sql-date-and-time-data-types'>SQL Date and Time Data Types <a href=\"#sql-date-and-time-data-types\" class=\"anchor\" id=\"sql-date-and-time-data-types\" title=\"Anchor for SQL Date and Time Data Types\">#<\/a><\/h2>\n\n\n\n<p>Date and time data types store calendar dates, times, or both.<\/p>\n\n\n\n<p>Here are the most common SQL data\/time types:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>DATE<\/li>\n\n\n\n<li>TIME<\/li>\n\n\n\n<li>TIMESTAMP<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='date'>DATE <a href=\"#date\" class=\"anchor\" id=\"date\" title=\"Anchor for DATE\">#<\/a><\/h3>\n\n\n\n<p>The <code>DATE<\/code> store a calendar date that includes: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>year <\/li>\n\n\n\n<li>month<\/li>\n\n\n\n<li>day. <\/li>\n<\/ul>\n\n\n\n<p>Typically, the range of the <code>DATE<\/code> The data type is from <code>0001-01-01<\/code> to <code>9999-12-31<\/code>.<\/p>\n\n\n\n<p>The date value is generally specified in the form:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">'YYYY-MM-DD'<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, the following <code>DATE<\/code> value is <code>December 31, 2020<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">'2020-12-31' <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-date'>When to use DATE <a href=\"#when-to-use-date\" class=\"anchor\" id=\"when-to-use-date\" title=\"Anchor for When to use DATE\">#<\/a><\/h3>\n\n\n\n<p>You use <code>DATE<\/code> for the date-only values, for example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>birth dates<\/li>\n\n\n\n<li>hire dates<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='time'>TIME <a href=\"#time\" class=\"anchor\" id=\"time\" title=\"Anchor for TIME\">#<\/a><\/h3>\n\n\n\n<p>The <code>TIME<\/code> data type stores values representing a time of day, including <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>hours<\/li>\n\n\n\n<li>minutes<\/li>\n\n\n\n<li>seconds.<\/li>\n<\/ul>\n\n\n\n<p>The <code>TIME<\/code> values should be specified in the following form:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">'HH:MM:SS'<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Some database systems support fractional seconds like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">'10:59:30.9999'<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-time'>When to use TIME <a href=\"#when-to-use-time\" class=\"anchor\" id=\"when-to-use-time\" title=\"Anchor for When to use TIME\">#<\/a><\/h3>\n\n\n\n<p>You use <code>TIME<\/code> to store time-only values like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>shift start times<\/li>\n\n\n\n<li>meeting times<\/li>\n\n\n\n<li>opening hours<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id='timestamp'>TIMESTAMP <a href=\"#timestamp\" class=\"anchor\" id=\"timestamp\" title=\"Anchor for TIMESTAMP\">#<\/a><\/h3>\n\n\n\n<p>The <code>TIMESTAMP<\/code> stores both a date and a time. <\/p>\n\n\n\n<p>A <code>TIMESTAMP<\/code> value is typically written like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">TIMESTAMP 'YYYY-MM-DD HH:MM:SS'<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Notice that there is a space separator between the date and time parts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='when-to-use-timestamp'>When to use TIMESTAMP <a href=\"#when-to-use-timestamp\" class=\"anchor\" id=\"when-to-use-timestamp\" title=\"Anchor for When to use TIMESTAMP\">#<\/a><\/h3>\n\n\n\n<p>You use <code>TIMESTAMP<\/code> for values that require both date and time, for example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Creation time<\/li>\n\n\n\n<li>Event logs<\/li>\n\n\n\n<li>Last updated time<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SQL data types define what kind of values a column can store.<\/li>\n\n\n\n<li>Use <code>CHAR<\/code> type for fixed-length text.<\/li>\n\n\n\n<li>Use <code>VARCHAR<\/code> type for variable-length text.<\/li>\n\n\n\n<li>Use <code>INT<\/code> type for whole numbers.<\/li>\n\n\n\n<li>Use <code>DECIMAL<\/code> type for exact values such as money.<\/li>\n\n\n\n<li>Use <code>FLOAT<\/code> type for approximate numeric values.<\/li>\n\n\n\n<li>Use <code>DATE<\/code> type for dates only.<\/li>\n\n\n\n<li>Use <code>TIME<\/code> type for time only.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1296\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-data-types\/\"\n\t\t\t\tdata-post-title=\"SQL Data Types\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1296\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqltutorial.org\/sql-data-types\/\"\n\t\t\t\tdata-post-title=\"SQL Data Types\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial introduces you to the most commonly used SQL data types including character string data types, numeric data types, and date time data types.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":35,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1296","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Data Types<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqltutorial.org\/sql-data-types\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Data Types\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqltutorial.org\/sql-data-types\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-01T09:21:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png\" \/>\n\t<meta property=\"og:image:width\" content=\"736\" \/>\n\t<meta property=\"og:image:height\" content=\"285\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/\",\"url\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/\",\"name\":\"SQL Data Types\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqltutorial.org\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types-300x116.png\",\"datePublished\":\"2018-01-17T13:31:46+00:00\",\"dateModified\":\"2026-04-01T09:21:53+00:00\",\"description\":\"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqltutorial.org\/sql-data-types\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage\",\"url\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png\",\"contentUrl\":\"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png\",\"width\":736,\"height\":285},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqltutorial.org\/sql-data-types\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqltutorial.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Data Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqltutorial.org\/#website\",\"url\":\"https:\/\/www.sqltutorial.org\/\",\"name\":\"SQL Tutorial\",\"description\":\"An Interactive SQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqltutorial.org\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Data Types","description":"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.","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:\/\/www.sqltutorial.org\/sql-data-types\/","og_locale":"en_US","og_type":"article","og_title":"SQL Data Types","og_description":"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.","og_url":"https:\/\/www.sqltutorial.org\/sql-data-types\/","og_site_name":"SQL Tutorial","article_modified_time":"2026-04-01T09:21:53+00:00","og_image":[{"width":736,"height":285,"url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/","url":"https:\/\/www.sqltutorial.org\/sql-data-types\/","name":"SQL Data Types","isPartOf":{"@id":"https:\/\/www.sqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage"},"image":{"@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types-300x116.png","datePublished":"2018-01-17T13:31:46+00:00","dateModified":"2026-04-01T09:21:53+00:00","description":"This tutorial introduces you to the most commonly used SQL data types including character string, numeric, and date time types.","breadcrumb":{"@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqltutorial.org\/sql-data-types\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/#primaryimage","url":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png","contentUrl":"https:\/\/www.sqltutorial.org\/wp-content\/uploads\/2018\/01\/SQL-Data-Types.png","width":736,"height":285},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqltutorial.org\/sql-data-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"SQL Data Types"}]},{"@type":"WebSite","@id":"https:\/\/www.sqltutorial.org\/#website","url":"https:\/\/www.sqltutorial.org\/","name":"SQL Tutorial","description":"An Interactive SQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/comments?post=1296"}],"version-history":[{"count":5,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1296\/revisions"}],"predecessor-version":[{"id":3648,"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/pages\/1296\/revisions\/3648"}],"wp:attachment":[{"href":"https:\/\/www.sqltutorial.org\/wp-json\/wp\/v2\/media?parent=1296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}