Re: novice: char to varchar

From: Date: Wed, 18 May 2005 21:31:04 +0000
Subject: Re: novice: char to varchar
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-215535@lists.php.net to get a copy of this message
On Wed, May 18, 2005 11:15 am, tony yau said:
Hi all, I try to do the following: CREATE TABLE IF NOT EXISTS Invoice( PKey INTEGER, Received DATETIME, Cost DECIMAL(10,2), FileName VARCHAR(50), RefNum CHAR(10), PRIMARY KEY (PKey) ) TYPE=MyISAM COMMENT='Invoice Data'; but it keep generating RefNum VARCHAR(10) instead of CHAR(10) I don't understand, please help (or point me to RTFM page)
WILD GUESS!!! In *some* impelementations of SQL, the performance benefit of CHAR over VARCHAR is lost after the first VARCHAR column.
That's exactly it... http://dev.mysql.com/doc/mysql/en/silent-column-changes.html If any column in a table has a variable length, the entire row becomes variable-length as a result. Therefore, if a table contains any variable-length columns (VARCHAR, TEXT, or BLOB), all CHAR columns longer than three characters are changed to VARCHAR columns. This doesn't affect how you use the columns in any way; in MySQL, VARCHAR is just a different way to store characters. MySQL performs this conversion because it saves space and makes table operations faster. See Chapter 14, MySQL Storage Engines and Table Types.

« previous php.general (#215535) next »