Differences between CHAR, VARCHAR data types in SQL Server

CHAR: 

CHAR stands for “Character”.

It is used for the fixed length of character data. 

The maximum length of character data should be 254 characters.

CHAR is a fixed length string data type, so any remaining space in the field is padded with blanks.

The default length for a CHAR is 1, and the maximum size of length is 254.

Storage size of CHAR datatypes is equal to n bytes i.e. set length

CHAR take 1 byte for each character

Better performance than VARCHAR


VARCHAR: 

VARCHAR stands for “Variable Character”.

It’s used for the variable length of character data. 

It is valid for a maximum of 4046 characters.

Since it is variable length it takes less memory spaces.

Decreases the performance of some SQL queries.

Storage size of VARCHAR datatype is equal to the actual length of the entered string in bytes.

VARCHAR take 1 byte for each character and some extra bytes for holding length information.

Performance is not good as compared to CHAR

It can hold numbers, letters and special characters.

No comments:

Post a Comment