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.

 

 

Slide10.JPG

Slide11.JPG
Slide12.JPG

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo