char 长度超过3就会自动转换成varchar

解决方案 »

  1.   

    没办法,一个表要么全是char,要么全是varchar,两者不能并存!
      

  2.   

    to binscut(何时走出迷雾) :
    可以并存只是在char超出范围是,才自动变成verchar
      

  3.   

    注意加*****的语句
    this is from mysql :
    -----------------------------------
    4.7.1 Silent Column Specification Changes
    In some cases, MySQL silently changes a column specification from that given in a CREATE TABLE statement. (This may also occur with ALTER TABLE.): VARCHAR columns with a length less than four are changed to CHAR. 
    If any column in a table has a variable length, the entire row is 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 section 5 MySQL Table Types. 
    TIMESTAMP display sizes must be even and in the range from 2 to 14. If you specify a display size of 0 or greater than 14, the size is coerced to 14. Odd-valued sizes in the range from 1 to 13 are coerced to the next higher even number. 
    You cannot store a literal NULL in a TIMESTAMP column; setting it to NULL sets it to the current date and time. Because TIMESTAMP columns behave this way, the NULL and NOT NULL attributes do not apply in the normal way and are ignored if you specify them. DESCRIBE tbl_name always reports that a TIMESTAMP column may be assigned NULL values. 
    MySQL maps certain column types used by other SQL database vendors to MySQL types. See section 4.3.8 Using Column Types from Other Database Engines. 
    If you want to see whether or not MySQL used a column type other than the one you specified, issue a DESCRIBE tbl_name statement after creating or altering your table. Certain other column type changes may occur if you compress a table using myisampack. See section 5.1.2.3 Compressed Table Characteristics. 
    -----------------------------------
      

  4.   

    谢谢楼上各位朋友的热心帮助。刚才我又建立了一个表,只有一个char字段(title)长度是255,一切正常。
    然后又建立了一个varchar字段,这时title自动变为varchar。我的表类型是MyISAMmysql设计的也太差了吧,char和varchar竟然不能同时存在?不可理解...有没有别的解决办法?
      

  5.   

    一旦有一个varchar,所有小于3个字节的char就会变为varchar
      

  6.   

    没有必要同时存在,让mysql自动优化好了