Jump to content


Photo

creating tables - varchar and char - odd thing happening


  • Please log in to reply
1 reply to this topic

#1 mfischer

mfischer
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 21 October 2003 - 06:25 PM

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

#2 yrrahxob

yrrahxob
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationKaty, Texas

Posted 09 November 2003 - 04:35 PM

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.
Harry R. Box
[br]We must all hang together or we shall surely hang separately.
[br]
[br]A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users