T-SQL Tutorial

Difference between Char and Varchar


Char vs Varchar

The CHAR is a data type with fixed length.
The CHAR uses the entire declared length even if fewer characters are stored in the variable.
The CHAR loads empty spaces.
The VARCHAR is a data type with variable length.
The VARCHAR does not use the entire declared length.
The VARCHAR uses only the length loaded with characters.
The Char and Varchar length must be a value from 1 through 8,000.





Example

DECLARE
@v_Char Char(10) = 'abcde',
@v_Varchar Varchar(10) = 'abcde'
SELECT
DATALENGTH(@v_Char) CharLen,
DATALENGTH(@v_Varchar) VarcharLen;

Results

CharLenVarcharLen
105