What is the difference between CHAR and VARCHAR2 datatype in SQL?

Asked: Apr 14, 2023

CHAR Datatype:

It is a datatype in SQL which is used to store character string of fixed length specified. If the length of string is less than set or fixed length then it is padded with extra blank spaces so that its length became equal to the set length. Storage size of CHAR datatype is of n bytes(set length). We should use this datatype when we expect the data values in a column are of same length. 

VARCHAR Datatype: It is a datatype in SQL which is used to store character string of variable length but maximum of set length specified. If the length of string is less than set or fixed length then it will store as it is without padded with extra blank spaces. Storage size of VARCHAR datatype is equal to the actual length of the entered string in bytes. We should use this datatype when we expect the data values in a column are of variable length. 

CHAR

VARCHAR

CHAR datatype is used to store character string of fixed length

VARCHAR datatype is used to store character string of variable length

In CHAR, If the length of string is less than set or fixed length then it is padded with extra memory space.

In VARCHAR, If the length of string is less than set or fixed length then it will store as it is without padded with extra memory spaces.

CHAR stands for “Character”

VARCHAR stands for “Variable Character”

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

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

We should use CHAR datatype when we expect the data values in a column are of same length.

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

CHAR take 1 byte for each character

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

Better performance than VARCHAR

Performance is not good as compared to CHAR

Asked by brijesh

Answers (0)

No answers yet. Be the first to answer!