Jump to content

creating tables - varchar and char - odd thing happening


mfischer

Recommended Posts

Hello,

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?

Thanks,

Maureen

Link to comment
Share on other sites

  • 3 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.