Search code examples
phpmysqlsqlalter-tablealter

Rename column name with php and MySql


I am trying to change the name of the column c to novaC with php and mysql. Everywhere I look seems to give the same solution but it doesn't seem to work:

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

If I type: ALTER TABLE aaa RENAME COLUMN c to novaC directly in MySql it gives:

 #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

Solution

  • alter table tablename change oldColumn newColumn varchar(10) ; 
    

    Reference : Alter Table - MySQL Command