char and varchar (T-SQL)

Character data types that are either fixed-length (char) or variable-length (varchar) and are in the code page of the server.

char[(n)]
Fixed-length non-Unicode character data with length of n characters. n must be a value from 1 through 8,000. Storage size is n bytes. The SQL-92 synonym for char is character.
varchar[(n)]
Variable-length non-Unicode character data with length of n characters. n must be a value from 1 through 8,000. Storage size is the actual length of the data entered, not n bytes. The data entered can be 0 characters in length. The SQL-92 synonyms for varchar are char varying or character varying.
Remarks

When n is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified with the CAST function, the default length is 30.

If SET ANSI_PADDING is OFF when CREATE TABLE or ALTER TABLE is executed, a char column defined as NULL is handled as varchar.

Use char when the data entries in a column are expected to be consistently close to the same size.

Use varchar when the data entries in a column are expected to vary considerably in size.

When the server code page uses double-byte characters, the storage size is still n bytes. Depending on the character string, the storage size of n bytes may be less than n characters.

See Also
CAST and CONVERT Data Types
Character Set sp_dbcmptlevel
Code Pages and Sort Orders Using char and varchar Data
Data Type Conversion Using Unicode Data

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.