CHAR (TSQL Datatype)
Is a fixed-length string datatype, with precision being the character length.
Syntax
CHAR [( precision )]
Remarks
The char
datatype is very much the same as varchar
, with the following differences:
char
is fixed-length. It is padded with blanks to the specified precision.- result of string functions and operators are always
varchar
, neverchar
.
The storage size of a char
data is not affected by the value of precision. Only the actual size of the data consumes memory or disk space. The padding blanks don’t consume disk space.
There is no reason to use the
char
datatype in real life. It is better to usevarchar
instead.
Examples
DECLARE @a CHAR(10) = 'The';
DECLARE @b CHAR(10) = 'Little';
DECLARE @c CHAR(10) = 'Mermaid';
PRINT @a + @b + @c + '!';
The result is:
The Little Mermaid !