2

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
6

2 Answers 2

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

Reference : Alter Table - MySQL Command

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

The MySQL documentation

2
  • 3
    The CHANGE requires you to specify the "column_definition" as well. So that query would cause an error.
    – Aaron W.
    Dec 26, 2012 at 17:06
  • @AaronW. oh sorry i forgot it! Dec 27, 2012 at 3:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.