mysql中如何修改列名?

解决方案 »

  1.   

    alter tabe ... oldName newName datatypemysql> create table t5 ( id int, col int);
    Query OK, 0 rows affected (0.11 sec)mysql>
    mysql> alter table t5 CHANGE col fld int;
    Query OK, 0 rows affected (0.06 sec)
    Records: 0  Duplicates: 0  Warnings: 0mysql> desc t5;
    +-------+---------+------+-----+---------+-------+
    | Field | Type    | Null | Key | Default | Extra |
    +-------+---------+------+-----+---------+-------+
    | id    | int(11) | YES  |     | NULL    |       |
    | fld   | int(11) | YES  |     | NULL    |       |
    +-------+---------+------+-----+---------+-------+
    2 rows in set (0.03 sec)mysql>
      

  2.   

    alter table tt CHANGE f1 f2 int
      

  3.   

    alter table tt modify f1 f2
    或者
    alter table change f1 f1 varchar