SQL data types define the type of value that can be stored in a table column. For example, if you want a column to store only integer values, you can define its data type as
SQL data types can be broadly divided into the following categories.
In this article, you will learn about different categories of SQL data types.
Note: Not all data types are supported by every relational database vendor.
For example, the Oracle database doesn’t support
DATETIME, and MySQL doesn’t support
CLOB. When designing database schemas and writing SQL queries, make sure to check if the data types are supported.
Note: Data types listed here don’t include all the data types. These are the most commonly used data types. Some relational database vendors have their own data types that might not be listed here.
For example, Microsoft SQL Server has
SMALLMONEY data types, but since they’re not supported by other popular database vendors, they’re not listed here.
Note: Every relational database vendor has its own maximum size limit for different data types.
Be sure to select the appropriate data type for your particular scenario.
|-10^38 + 1
|10^38 - 1
|-10^38 + 1
|10^38 - 1
|Stores date in the format
|Stores time in the format
|Stores date and time information in the format
|Stores number of seconds passed since the Unix epoch (
'1970-01-01 00:00:00' UTC)
|Stores year in a 2-digit or 4-digit format. Range 1901 to 2155 in 4-digit format. Range 70 to 69, representing 1970 to 2069.
|Fixed length with a maximum length of 8,000 characters
|Variable-length storage with a maximum length of 8,000 characters
|Variable-length storage with provided max characters, not supported in MySQL
|Variable-length storage with a maximum size of 2GB data
Note: These data types are for character streams. They should not be used with Unicode data.
|Fixed length with a maximum length of 4,000 characters
|Variable-length storage with a maximum length of 4,000 characters
|Variable-length storage with provided max characters
|Variable-length storage with a maximum size of 1GB data
Note: These data types are not supported in MySQL databases.
|Fixed length with a maximum length of 8,000 bytes
|Variable-length storage with a maximum length of 8,000 bytes
|Variable-length storage with provided max bytes
|Variable-length storage with a maximum size of 2 GB binary data
|Character large objects that can hold up to 2 GB
|For large binary objects
|For storing XML data
|For storing JSON data
In this article, you learned about different categories of SQL data types.
Continue your learning with more SQL tutorials.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.