SQL - Data Types
SQL - Data Types
SQL Data Type is an attribute that specifies the type of data of any object. Each column, variable
and expression has a related data type in SQL. You can use these data types while creating your
tables. You can choose a data type for a table column based on your requirement.
SQL Server offers six categories of data types for your use which are listed below −
tinyint 0 255
bit 0 1
Note − Here, datetime has 3.33 milliseconds accuracy where as smalldatetime has 1 minute
accuracy.
char
1
Maximum length of 8,000 characters.( Fixed length non-Unicode characters)
varchar
2
Maximum of 8,000 characters.(Variable-length non-Unicode data).
varchar(max)
3 Maximum length of 2E + 31 characters, Variable-length non-Unicode data (SQL Server
2005 only).
text
4
Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters.
nchar
1
Maximum length of 4,000 characters.( Fixed length Unicode)
2
nvarchar
Maximum length of 4,000 characters.(Variable length Unicode)
nvarchar(max)
3 Maximum length of 2E + 31 characters (SQL Server 2005 only).( Variable length
Unicode)
ntext
4
Maximum length of 1,073,741,823 characters. ( Variable length Unicode )
binary
1
Maximum length of 8,000 bytes(Fixed-length binary data )
varbinary
2
Maximum length of 8,000 bytes.(Variable length binary data)
varbinary(max)
3
Maximum length of 2E + 31 bytes (SQL Server 2005 only). ( Variable length Binary data)
image
4
Maximum length of 2,147,483,647 bytes. ( Variable length Binary Data)
sql_variant
1 Stores values of various SQL Server-supported data types, except text, ntext, and
timestamp.
timestamp
2
Stores a database-wide unique number that gets updated every time a row gets updated
uniqueidentifier
3
Stores a globally unique identifier (GUID)
xml
4 Stores XML data. You can store xml instances in a column or a variable (SQL Server
2005 only).
cursor
5
Reference to a cursor object
table
6
Stores a result set for later processing