Difference between CHAR and VARCHAR is SQL

 CHAR is used to store a character string of fixed size.

CHAR Uses Static memory allocation i.e. if length 10 is defined and the character string size is 6 then, still the variable will hold 10 characters in memory.

VARCHAR is used to store character string of variable size.

Varchar uses dynamic memory allocation i.e. only the memory corresponding to the character string length will be occupied.

Eg.,

CREATE TABLE Account( Id Integer, UserName char(10), City varchar );

INSERT INTO Account VALUES (1,"Krunal","Pune");

SELECT LENGTH(UserName) FROM Account where id=1;

Output:- 10

SELECT LENGTH(City) FROM Account where id=1;

Output:- 4


Comments

Popular posts from this blog

Jenkins CICD in One Page

Why do we need a build tool?

Deutsche Bank Interview Questions - 2024