SQL Data Types
SQL data types are divided into five categories:
- Character/String Data Types
- Numeric Data Types
- Date/Time Data Types
- Binary Data Types
- Miscellaneous Data Types
1. Character/String Data Types
Character/Strings can be used to store strings like names, locations, etc. and even large text files.
| Data Type | Description |
|---|---|
| CHAR | Maximum 8000 character long fixed length string |
| VARCHAR | Maximum 8000 character long variable length string |
| VARCHAR(max) | Maximum max character long variable length string |
| NCHAR | Unicode Maximum 8000 character long fixed length string |
| NVARCHAR | Unicode Maximum 8000 character long variable length string |
| NVARCHAR(max) | Unicode Maximum max character long variable length string |
| TEXT | Maximum 2GB sized variable length string |
2. Numeric Data Types
Numeric data types can be used to store exact or decimal numeric data, from very small numbers in a bit or tinyint to very large numbers in a bigint.
| Data Type | Minimum | Maximum |
|---|---|---|
| bit | 0 | 1 |
| tinyint | 0 | 255 |
| smallint | -32,768 | 32,767 |
| int | -2,147,483,648 | 2,147,483,647 |
| bigint | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
| decimal | -10^38 - 1 | -10^38 - 1 |
| real | -3.40E + 38 | 3.40E + 38 |
| numeric | -10^38 +1 | 10^38 -1 |
| float | -1.79E + 308 | 1.79E + 308 |
3. Date/Time Data Types
Date/Time data types are used to store data and time objects. Storing a date as a date/type object instead of a string can make it very easy to work with data at a later point.
| Data Type | Description |
|---|---|
| Datetime | Date and Time stored in the YYYY-MM-DD HH:MI:SS format |
| Date | Date stored in the YYYY-MM-DD format |
| Time | Time stored in the HH:MI:SS format |
| Timestamp | Number of seconds passed stored since ‘1970-01-01 00:00:00’ UTC |
| Year | Year stored in 2-digit (from 1970-2069) or 4-digit (from 1901 2155) format |
4. Binary Data Types
Binary data types are used to store data in its binary form, instead of storing it as strings, which can be a big factor in saving space.
| Data Type | Description |
|---|---|
| BINARY | Maximum length of 8000 bytes fixed binary |
| VARBINARY | Maximum length of 8000 bytes variable binary |
| VARBINARY(max) | Maximum length of max bytes fixed binary |
| NTEXT | Maximum 2GB sized variable length binary |
5. Miscellaneous Data Types
These data types are for special types of data as described below:
| Data Type | Description |
|---|---|
| CLOB | Upto 2GB large character objects |
| BLOB | For storing binary large objects |
| JSON | For storing JSON objects |
| XML | For storing XML objects |
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved