使用php和MySql重命名列名

时间:2012-12-26 16:45:06

标签: php mysql sql alter-table alter

我正在尝试使用php和mysql将列c的名称更改为novaC。我看的每个地方似乎都提供相同的解决方案,但它似乎不起作用:

if(isset($_GET["rename"])){
    mysql_query("ALTER TABLE myTable
    RENAME COLUMN c to novaC");
}

如果我直接在MySql中键入:ALTER TABLE aaa RENAME COLUMN c to novaC,则会给出:

 #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COLUMN c to novaC' at line 2

2 个答案:

答案 0 :(得分:5)

if(isset($_GET["rename"])){ 
    mysql_query("ALTER TABLE myTable CHANGE c  novaC varchar(9999)"); 
}

The MySQL documentation

答案 1 :(得分:5)

alter table tablename change oldColumn newColumn varchar(10) ; 

Reference : Alter Table - MySQL Command