加载中...

Databases

  1. Home
  2. Computing & Technology
  3. Databases

Character String Data Types in SQL Server

By Mike Chapple, About.com

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

Explore Databases

More from About.com

New Year, New You

Take action today to accomplish your biggest goals with these motivating ideas.

Best Moves in a Bad Economy

Stay on top in this tough economy with our smart, easy-to-follow financial tips.

Databases

  1. Home
  2. Computing & Technology
  3. Databases
  4. SQL Server
  5. Character String Data Types in SQL Server

©2009 About.com, a part of The New York Times Company.

All rights reserved.