Thanks for the explaination. Heh I should have realized that. varchars are probably implemented as null terminated strings and so they need an extra byte for the terminating char (Null or otherwise).
They're stored as a length byte + string contents.
Yeah it's definitely doing me a favor as my reason for varchar was space. So what happens if I store a single char in a field of char(2)? Does it get autofilled then? I saw an option for this so do I have to specify that this field should get autofilled?
The answer to this is to do what you indicate you already know that you should do in the next sentence. :-) Spending some time in the column types chapter will give you some useful background.
I'm definitely gonna have to read that manual you gave me the link to I see. That default thing means I'm gonna have to re-do all the SQL in that application. *sigh* I just knew I would. I fought a good fight I guess.
On Sun, 18 Apr 2004 15:03:18 -0400, Michael Stassen wrote:
In MySQL, the only practical difference between a CHAR and a VARCHAR is how it is stored. CHARs are fixed-length, so they are fast but can waste space. VARCHARs are variable length, so they are slow but (usually) save space. That's the key here -- the only advantage to a varchar is the space savings. But, each varchar takes one more byte than the length of the string in order to store the length. When your column is less than 4 characters, that extra byte makes a significant dent in your space savings, thus removing the sole advantage of varchar over char. For example, it takes 2 bytes to store a CHAR(2) and 1 to 3 bytes to store a VARCHAR(2). MySQL is trying to do you a favor by changing your column. Whether you agree it's done you a favor or not seems to be a matter of opinion.
You should definitely read the "Silent Column Specification Changes" <http://dev.mysql.com/doc/mysql/en/Silent_column_changes.html> section of the manual.
Michael
-- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Stormblade (Shaolin Code Warrior) Software Developer (15+ Years Programming exp.)
My System: http://www.anandtech.com/mysystemrig.html?rigid=1683 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-- Paul DuBois, MySQL Documentation Team Madison, Wisconsin, USA MySQL AB, www.mysql.com
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]