Check sibling questions

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.

 

 

Are ads bothering you?

Davneet Singh's photo - Teacher, Engineer, Marketer

Made by

Davneet Singh

Davneet Singh is a graduate from Indian Institute of Technology, Kanpur. He has been teaching from the past 12 years. He provides courses for Maths and Science at Teachoo.