Jump to content


This topic is now archived and is closed to further replies.


creating tables - varchar and char - odd thing happening

Recommended Posts


I used the book PHP fast & easy book which had some PHP code for creating

tables. THe code worked but mysql seems to change (with no pattern that I can understand varchar to char and visa versa). I have printed out the sql create statement prior to executing it that is built by the PHP code


for instance : CREATE TABLE teacher (id char (5) not null,name varchar (40) not null,email varchar (30) null,level varchar (5) null, UNIQUE id(id))


but when I look at the table using the explain command

all the fields are defined as varchar. The size of the field and other

options I selected are correct.




Any ideas?



Share this post

Link to post
Share on other sites

I wouldn\'t worry about it. Mysql automatically converts char to vchar if the field is over 3 or 4 bytes long. This is to save disk space for tables having an extremely large number of rows. Imagine a field that took up 500 bytes but only held 25 bytes of data but the table had 10 million records. lots of wasted space there.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.