Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993
Question 12: Which table will use less storage? – MySQL Question of the Day

Skip to content

By urs in mysql questions

 
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 ]
 

Tags: , ,

Comment Feed

One Response


  1. 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:

    - show table status like 'chartst%';
    - select table_schema,table_name,data_length
      from information_schema.tables
      where table_schema='TT' and table_name like 'chartst%';

You must be logged in to post a comment.