Tutorialsteacher

Follow Us

SQL Server Data Types

In SQL Server, data type specifies the type of data that can be stored in a column of a table such as integer data, string data, date & time, binary strings, etc.

Assigning an appropriate data type to columns in a table is crucial while designing a database. It affects the performance and efficiency of the database and the application using the database.

SQL Server provides built-in data types for all kinds of data that can be used within SQL Server. Additionally, you can also define your own data type in T-SQL.

Data Type Categories:

CategoryData Types
Exact numericsbit, tinyint, smallint, int, bigint, decimal, numeric, money, smallmoney
Approximate numericsReal, Float
Date & Timedate, smalldatetime, datetime, datetime2, datetimeoffset, time
Character stringschar, varchar, text
Unicode Character stringsnchar, nvarchar, ntext
Other data typescursor, hierarchyid, sql_variant, spatial Geometry types, spatial Geography types, rowversion, uniqueidentifier, xml, table

Exact Numerics

Data TypeValueDescription
bit0,1 or NULLSmallest data type of 1 byte storage size
tinyint0 to 2551 bytes storage size
smallint-32,768 to 32,7672 bytes storage size
int−2,147, 483,6484 bytes storage
bigint−9,223,372, 036,854,775,8088 bytes storage
decimal−10^38+1 to 10^38−1Numeric data type that have a fixed precision and scale.
smallmoney-214,748.3648 to 214,748.36474 bytes
money-922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytes

Approximate Numerics

Data TypeValueDescription
float(n)- 1.79E+308 to -2.23E-308, 0Storage depends on the value of n.
real- 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 384 bytes

Date and Time

Data TypeValueDescription
date0001-01-01 through 9999-12-313 bytes
datetimeDate: 1753-01-01 through 9999-12-318 bytes
datetime2Date: 0001-01-01 through 9999-12-31Precision < 3 : 6 bytes
smalldatetime1900-01-01 through 2079-06-064 bytes fixed
datetimeoffsetDate: 0001-01-01 through10 bytes fixed
time00:00:00.0000000 through 23:59:59.99999995 bytes fixed

Character Strings

Data TypeValueDescription
char[(n)]1 to 8000 charactersn bytes
varchar[(n)]1 to 8000n bytes + 2 bytes
varchar(max)1 to 2^31-1n bytes + 4 bytes
text0 to 2,147,483,647n bytes + 4 bytes

Unicode Character Strings

Data TypeValueDescription
nchar[(n)]1 to 4000 characters2 times n bytes
nvarchar[(n|max)]1 to 40002 times n bytes
ntext0 to 1,073,741,8232 times the string length

Binary Strings

Data TypeValueDescription
binary[(n)]1 to 8000 bytesn bytes
varbinary[(n|max)]1 to 8000Actual length of string + 2 bytes
Image0 to 2,147,483,647Variable length binary data

Other Data Types

Data typeDescription
cursorA data type for variables or stored procedures OUTPUT parameters that contain a reference to a cursor.
rowversionIt returns automatically generated unique binary numbers within a database.
hierarchyidIt is a variable length system data type.
uniqueidentifierIs a 16 byte GUID
sql_variantA data type that stores values of various SQL Server supported data types.
xmlIt stores xml data.
Spatial Geometry typeUsed to represent data in a flat coordinate system (Euclidean).
tableIt is a special data type used to store a result-set temporarily for processing at a later time.