SQL

SQL Server data types

Numeric data types:

Precision: Total number of digits

Scale: Number of digits to the right of the decimal

Data typeBytes
bit1
tiny int1
small int2
int4
big int8
numeric(precision,scale)depends on precision
decimal(precision,scale)depends on precision
float(n)depends on n
real4
small money4
money8

Char and varchar data types:

Char is fixed length and varchar is variable length

Data typeRange
char(n)1 to 8000
varchar(n)1 to 8000
varchar(max)2^31-1

Unicode data types: supports all languages

Data typeRange
nchar(n)1 to 4000
nvarchar(n)1 to 4000
nvarchar(max)2^30-1

Date data types:

Data typeBytesDescription
Date3
small datetime4Rounded to nearest minute
datetime8has fractional seconds
datetime26 to 8Precise to nanoseconds
datetimeoffset10Stores offset between local time and UTC
time5

Binary data types:

Data typeRangeDescription
binary0 to 8000stores images, text etc
varbinary0 to 8000stores images, text etc

Other data types:

Data typeDescription
timestampIt is an autogenerated number
uniqueidentifierIt is a 16 byte GUID
sql_variantStores values of various data types
cursorUsed for variables
xmlUsed to store xml data