Check out the following situation:
create table chartst1 (a char(2)); create table chartst2 (a varchar(2)); insert into chartst1 values ('xx'),('Xx'),('x1'),('x2'),('3x'); insert into chartst2 values ('xx'),('Xx'),('x1'),('x2'),('3x');
Which table will use less storage?
a) chartst1 b) chartst2 c) both tables use the same storage, as the data is the same
Extra question: how would you check?
[ Data Types (15%) - String Data Types ]
Answer:
a
The total size depends also on the charset, but in general
varchar
has to store the column value together with the length.char
“knows” the length, as it is fixed.With MyIsam, the varchar also causes the row format to be dynamic.
You can check with: