SQL Data Types
This document provides a comprehensive reference to the data types supported by SQL Server. Understanding these data types is crucial for designing efficient and robust databases.
Numeric Data Types
Data Type | Description | Storage | Range |
---|---|---|---|
INT |
Standard integer data type. | 4 Bytes | -2,147,483,648 to 2,147,483,647 |
BIGINT |
Large integer data type. | 8 Bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
SMALLINT |
Small integer data type. | 2 Bytes | -32,768 to 32,767 |
TINYINT |
Very small integer data type. | 1 Byte | 0 to 255 |
DECIMAL / NUMERIC |
Exact fixed-point number. Specified with precision and scale. | Variable (up to 17 Bytes) | Precision: 1-38, Scale: 0-38 |
FLOAT / REAL |
Approximate floating-point number. | 4 or 8 Bytes | Approximate ranges depend on precision. |
MONEY |
Currency data type. Stores values in monetary units. | 8 Bytes | -922,337,203,685,477.5808 to 922,337,203,685,477.5807 |
SMALLMONEY |
Smaller currency data type. | 4 Bytes | -214,748.3648 to 214,748.3647 |
Date and Time Data Types
Data Type | Description | Storage | Range |
---|---|---|---|
DATE |
Stores date values. | 3 Bytes | 0001-01-01 to 9999-12-31 |
TIME |
Stores time values. | 3 to 5 Bytes | 00:00:00.0000000 to 23:59:59.9999999 |
DATETIME |
Stores date and time values. | 8 Bytes | January 1, 1753, through December 31, 9999 |
DATETIME2 |
Enhanced date and time values. Higher precision than DATETIME. | 6 to 8 Bytes | January 1, 0001, through December 31, 9999 |
SMALLDATETIME |
Stores date and time values with less precision. | 4 Bytes | January 1, 1900, through June 3, 2079 |
DATETIMEOFFSET |
Stores date and time values with time zone offset. | 8 to 10 Bytes | January 1, 0001, through December 31, 9999 |
SMYSDATETIME |
A future data type for enhanced date and time storage. | N/A | N/A |
String Data Types
Data Type | Description | Storage | Max Length |
---|---|---|---|
VARCHAR |
Variable-length, non-Unicode character data. | N+2 Bytes | 8000 characters |
NVARCHAR |
Variable-length, Unicode character data. | 2N+2 Bytes | 4000 characters |
CHAR |
Fixed-length, non-Unicode character data. | N Bytes | 8000 characters |
NCHAR |
Fixed-length, Unicode character data. | 2N Bytes | 4000 characters |
TEXT |
Variable-length, non-Unicode character data (legacy). | N+2 Bytes | 2 GB |
NTEXT |
Variable-length, Unicode character data (legacy). | 2N+2 Bytes | 1 GB |
VARCHAR(MAX) |
Variable-length, non-Unicode character data (large value). | N+2 Bytes | 2 GB |
NVARCHAR(MAX) |
Variable-length, Unicode character data (large value). | 2N+2 Bytes | 1 GB |
Binary Data Types
Data Type | Description | Storage | Max Length |
---|---|---|---|
BINARY |
Fixed-length binary data. | N Bytes | 8000 Bytes |
VARBINARY |
Variable-length binary data. | N+2 Bytes | 8000 Bytes |
IMAGE |
Variable-length binary data (legacy). | N+2 Bytes | 2 GB |
VARBINARY(MAX) |
Variable-length binary data (large value). | N+2 Bytes | 2 GB |
FILESTREAM |
Stores large binary objects (BLOBs) in the file system. | Variable | Up to 1 GB (file system limits) |
Important Note: The
TEXT
, NTEXT
, and IMAGE
data types are deprecated. It is recommended to use VARCHAR(MAX)
, NVARCHAR(MAX)
, and VARBINARY(MAX)
respectively for new development.
Other Data Types
Data Type | Description |
---|---|
BIT |
Boolean data type, stores 0, 1, or NULL. |
UNIQUEIDENTIFIER |
Globally Unique Identifier (GUID). |
XML |
Stores XML data. |
JSON |
Stores JSON data. |
GEOMETRY |
Spatial data type for geometric shapes. |
GEOGRAPHY |
Spatial data type for geographic locations. |
HIERARCHYID |
Stores data representing a hierarchy. |
SQL_VARIANT |
Stores values of various supported SQL Server data types. |
For detailed information on the behavior, storage, and usage of each data type, please refer to the specific documentation pages linked within the navigation pane.