Differentiate between char(n) and varchar(n) data types with respect to databases.
Answer
char(n) |
varchar(n) |
Char is a datatype in SQL which is used to store character/s or string of fixed length between 1 and 255 characters. |
Varchar is a datatype in SQL which is used to store alphanumeric data of variable length but maximum length which is specified |
In this, If the length of string is less than specified length then extra memory spaces is added automatically |
In this, If the length of string is less than specified length then the string will be stored as it is i.e. no extra memory spaces. |
In this, some space gets wasted |
In this, no space gets wasted |
Storage size of char data types is equal to n bytes i.e. specified length . |
Storage size of varchar datatype is equal to the actual length of the entered string in bytes. |