Char
and varchar
are datatypes in SQL, as they are in many other languages(So this question could be multi-language).
From what I understand, the difference is that if I declared a Char
as Char(20)
it would allocate 20 (bytes/bits) [Could someone clarify this bit too? For now, I'll use bytes.]. Then if I only used 16 bytes, I would still have four allocated to that field. (A waste of 4 bytes of memory.)
However, if I declared a varchar
as varchar(20)
and only used 16 bytes, it would only allocate 16 bytes.
Surely this is better? Why would anyone choose char
? Is it foe legacy reasons, or is there something I'm missing?