Data Types

Now you may be wondering, data types, isn't this section all about expressions and functions? You are correct. However, before discussing those important aspects of T-SQL, here's a quick overview of the various data types available in SQL Server. Understanding these different types are pivotal when it comes to building expressions and using the scalar functions in an effective and efficient manner.

Character Data Types

SQL Server supports several character data types, as listed in Table 8.1.

Table 8.1 Character Data Types

Data Type Description Size in Bytes
Char(n) Fixed-length character data up to 8,000 characters long using collation character set Defined length * 1 byte
Nchar(n) Unicode fixed-length character data Defined length * 2 bytes
VarChar(n) Variable-length character data up to 8,000 characters long using collation character set 1 byte per character
VarChar(max) Variable-length character data up to 2GB in length using collation character set 1 byte per character
nVarChar(n) Unicode variable-length character data up to 8,000 characters long using collation character set 2 bytes per character
nVarChar(max) Unicode variable-length character data up to 2GB in length using collation character set 2 bytes per character
Text Variable-length character data up to 2,147,483,647 characters in length Warning: Deprecated 1 byte per character
nText Unicode variable-length character data up to 1,073,741,823 characters in length Warning: Deprecated 2 bytes per ...

Get Microsoft SQL Server 2012 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.