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

 

Remove Ads
Teachoo · Class 12 Explore Class 12
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.