+ 1

What is the difference between char and varchar in sql???

17th Apr 2017, 7:33 PM
CHANDRA MANI PANDEY
CHANDRA MANI PANDEY - avatar
3 Answers
+ 1
i would like to explain you with an analogy of varchar with polythene bag and char with wooden box. Now if you have some item to store in a Box the volume occupied by the box will be constant. But if we take polythene bag we could wrap the content to the same volume of the item so as to reduce the space required to keep the polythene bag. Now I guess u might have got some clue . Varchar has a certain limit (same with polythene bag i.e it can keep a certain volume of item in it) but Varchar helps us to reduce the memory requirement to avoid memory wastage but in case of char i.e the wooden box it would occpy the whole area even if we want to keep a needle in it. i.e it cannot wrap its length to the variable's length.
17th Apr 2017, 8:58 PM
Yash Tiwari
Yash Tiwari - avatar
+ 5
http://stackoverflow.com/questions/3887735/mysql-difference-between-char-and-varchar from the page above: "VARCHAR stores a variable number of bytes for only the space required by the content. CHAR stores a fixed size of however many bytes you specify for your table, no matter how many characters occupy a field of this type per row."
17th Apr 2017, 7:51 PM
Burey
Burey - avatar
0
char(Character) can hold only 255 character. but varchar(variable length character) can hold up to over 25,000. For larger input, use text instead of varchar. It can hold a large a mount of character.
17th Apr 2017, 8:44 PM
Sai Saing Hmine Tun
Sai Saing Hmine Tun - avatar