Character strings

Character strings#

Non-Unicode character data, stored in the server’s code page. Character data can be fixed-length (char) or variable-length (varchar); fixed-length strings are right-padded with spaces on output, variable-length strings are not. text is the legacy large-object variant.

  • char

  • varchar

  • text

char and varchar#

String data types of either fixed length or variable length.

Example:

DECLARE @myVariable AS varchar = 'xyz';
SELECT @myVariable as aVarchar;

text#

Variable-length non-Unicode data in the code page of the server, with a maximum string length of 2^31-1 (2,147,483,647). When the server code page uses double-byte characters, the storage is still 2,147,483,647 bytes; depending on the character string, the storage size may be less.

Example:

SELECT cast('Lorem ipsum dolor sit amet...' as text);

See also#