1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

Character String Data Types in SQL Server

By

Character string data types are used to store text values in Microsoft SQL Server databases.

Data types in the character string category include:
  • char(n) variables store fixed-length character strings conisisting of exactly n characters (and, therefore, n bytes). They are limited to 8,000 characters in size.
  • nchar(n) variables store fixed-length Unicode character strings conisisting of exactly n characters (and, therefore, 2*n bytes). They are limited to 4,000 characters in size.
  • varchar(n) variables store non-fixed length character strings consisting of approximately n characters. They consume l+2 bytes of space, where l is the actual length of the string. They are limited to 8,000 characters in size.
  • nvarchar(n) variables store non-fixed length Unicode character strings consisting of approximately n characters. They consume 2*l+2 bytes of space, where l is the actual length of the string. They are limited to 4,000 characters in size.
  • varchar(max) variables store non-fixed length character strings consisting of up to 1,073,741,824 characters. They consume l+2 bytes of space, where l is the actual length of the string.
  • nvarchar(max) variables store non-fixed length Unicode character strings consisting of up to 536,870,912 characters. They consume l*2+2 bytes of space, where l is the actual length of the string.
  • text and ntext variables store up to 2GB of text data (ANSI and Unicode, respectively), but can not be used in many text operations. Therefore, they are usually only used to support legacy applications and have been replaced by the varchar(max) and nvarchar(max) data types.
If the character string data types don’t suit your needs, read more about other SQL Server data types.
  1. About.com
  2. Technology
  3. Databases
  4. SQL Server
  5. Character String Data Types in SQL Server

©2014 About.com. All rights reserved.