O'Reilly logo

Microsoft SQL Server 2012 Bible by Aaron Nelson, Jose Chinchilla, Patrick LeBlanc, Jorge Segarra, Adam Jorgensen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required