While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
SQL Data Types define the type of value that can be stored in a table column. For example, if we want a column to store only integer values, then we can define its data type as
SQL data types can be broadly divided into following categories.
smallmoneydata types but since it’s not supported by other popular database vendors, it’s not listed here.
Let’s look into different categories of SQL data types in detail.
|bigint||-9,223,372,036, 854,775,808||9,223,372,036, 854,775,807|
|decimal||-10^38 +1||10^38 -1|
|numeric||-10^38 +1||10^38 -1|
|float||-1.79E + 308||1.79E + 308|
|real||-3.40E + 38||3.40E + 38|
|DATE||Stores date in the format YYYY-MM-DD|
|TIME||Stores time in the format HH:MI:SS|
|DATETIME||Stores date and time information in the format YYYY-MM-DD HH:MI:SS|
|TIMESTAMP||Stores number of seconds passed since the Unix epoch (‘1970-01-01 00:00:00’ UTC)|
|YEAR||Stores year in 2 digits or 4 digit format. Range 1901 to 2155 in 4-digit format. Range 70 to 69, representing 1970 to 2069.|
|CHAR||Fixed length with a maximum length of 8,000 characters|
|VARCHAR||Variable-length storage with a maximum length of 8,000 characters|
|VARCHAR(max)||Variable-length storage with provided max characters, not supported in MySQL|
|TEXT||Variable-length storage with maximum size of 2GB data|
Note that all the above data types are for character stream, they should not be used with Unicode data.
|NCHAR||Fixed length with maximum length of 4,000 characters|
|NVARCHAR||Variable-length storage with a maximum length of 4,000 characters|
|NVARCHAR(max)||Variable-length storage with provided max characters|
|NTEXT||Variable-length storage with a maximum size of 1GB data|
Note that above data types are not supported in MySQL database.
|BINARY||Fixed length with a maximum length of 8,000 bytes|
|VARBINARY||Variable-length storage with a maximum length of 8,000 bytes|
|VARBINARY(max)||Variable-length storage with provided max bytes|
|IMAGE||Variable-length storage with maximum size of 2GB binary data|
|CLOB||Character large objects that can hold up to 2GB|
|BLOB||For binary large objects|
|XML||for storing XML data|
|JSON||for storing JSON data|
That’s all for a quick roundup on SQL data types.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up
Click below to sign up and get $100 of credit to try our products over 60 days!