I'm a very newbie to mysql. My tables hold data that is usually limited in length. As I understand it, if a field is definitely going to be limited to, say, 50 characters, I should use varchar, whereas if it will be unlimited, or at least over 200 chars or so, I should use a text field?
Is this right? Am I missing something?
Some more info
mysql field types [scibit.com]
If you know for certain that your field is shorter than 255 you can use a varchar field. If you put something too long (longer than the declared length of the field) into a varchar field, it is simply truncated.
You only need text fields if your field can be longer than 255 characters.
If this field is the only varchar in a table, you can use a char field to speed things up. It has a fixed length, so the whole record will have fixed length, giving MySQL a possibility to optimise accesses. If you have just one variable length field in a table, all other char fields are silently converted to varchar.
René
[php.net...]
So by changing from text to varchar you save one byte per record but no time. If you want to save time, you have to change all your fields to fixed length char fields. That'll cost you some space.
You can change you table layout with the ALTER TABLE command in MySQL. See
[mysql.com...]
You'll need a command like (field is a text field):
ALTER TABLE tablename CHANGE field field VARCHAR(size) ...;
The first "field" is the name of field you what to change and the second "field" is the new name. They can be the same.
René.