Data Types

This section provides a comprehensive overview of the data types supported by the SQL Server Database Engine, including their syntax, storage, and typical usage.

Exact Numeric Data Types

These data types store numeric values precisely. They are suitable for calculations where exact precision is critical, such as financial transactions.

Integer Types

Data Type Storage Size Range Description
TINYINT 1 byte 0 to 255 Unsigned integer
SMALLINT 2 bytes -32,768 to 32,767 Signed integer
INT 4 bytes -2,147,483,648 to 2,147,483,647 Signed integer
BIGINT 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 Signed integer

Approximate Numeric Data Types

Data Type Storage Size Precision Range Description
FLOAT 4 or 8 bytes 7 or 15 digits approx. +/- 1.79E-308 to +/- 1.79E+308 Floating point number
REAL 4 bytes 7 digits approx. +/- 1.79E-308 to +/- 1.79E+308 Floating point number (synonym for float(24))

Fixed Point Numeric Data Types

Data Type Storage Size Precision Scale Description
DECIMAL(p, s) Variable 1 to 38 0 to p Fixed precision and scale
NUMERIC(p, s) Variable 1 to 38 0 to p Synonym for DECIMAL
MONEY 8 bytes 19, 4 Four decimal places Monetary values
SMALLMONEY 4 bytes 10, 4 Four decimal places Smaller monetary values

Date and Time Data Types

These data types store date and time information. They are crucial for auditing, scheduling, and time-series analysis.

Data Type Storage Size Range Precision Description
DATE 3 bytes January 1, 0001 to December 31, 9999 N/A Date only
TIME 3-5 bytes 00:00:00.0000000 to 23:59:59.9999999 100 nanoseconds (configurable) Time only
DATETIME 8 bytes January 1, 1753 to December 31, 9999 3.33 milliseconds Date and Time
DATETIME2(n) 6-8 bytes January 1, 0001 to December 31, 9999 100 nanoseconds (configurable) Date and Time with higher precision
SMALLDATETIME 4 bytes January 1, 1900 to June 6, 2079 1 minute Date and Time (less precise)
DATETIMEOFFSET(n) 8-10 bytes January 1, 0001 to December 31, 9999 100 nanoseconds (configurable) Date and Time with Time Zone Offset

Character String Data Types

These data types store textual data. They are essential for storing names, addresses, descriptions, and other text-based information.

Data Type Storage Max Length Description
CHAR(n) n bytes 8,000 characters Fixed-length, non-Unicode string
VARCHAR(n) 2 bytes + data 8,000 characters Variable-length, non-Unicode string
VARCHAR(MAX) 2 bytes + data 2 GB Variable-length, non-Unicode string (large)
NCHAR(n) 2n bytes 4,000 characters Fixed-length, Unicode string
NVARCHAR(n) 2n + 2 bytes 4,000 characters Variable-length, Unicode string
NVARCHAR(MAX) 2n + 2 bytes 2 GB Variable-length, Unicode string (large)
TEXT Variable 2 GB Non-Unicode string (deprecated)
NTEXT Variable 2 GB Unicode string (deprecated)

Binary String Data Types

These data types store binary data, such as images, files, or other raw byte sequences.

Data Type Storage Max Length Description
BINARY(n) n bytes 8,000 bytes Fixed-length binary string
VARBINARY(n) 2 bytes + data 8,000 bytes Variable-length binary string
VARBINARY(MAX) 2 bytes + data 2 GB Variable-length binary string (large)
IMAGE Variable 2 GB Binary data (deprecated)

Other Data Types

This category includes a variety of specialized data types for different purposes.

Data Type Storage Description
BIT 1 bit Stores 0, 1, or NULL. Used for Boolean values.
UNIQUEIDENTIFIER 16 bytes Stores a GUID (Globally Unique Identifier).
XML Variable Stores XML data.
GEOGRAPHY Variable Stores geographic data (points, lines, polygons).
GEOMETRY Variable Stores spatial data (points, lines, polygons).
HIERARCHYID Variable Stores data in a hierarchy.
SQL_VARIANT Variable Stores values of various supported data types.
TABLE Variable Stores a result set for later use.
Back to Top