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

Sign up to request clarification or add additional context in comments.

Comments

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

The MySQL documentation

2 Comments

The CHANGE requires you to specify the "column_definition" as well. So that query would cause an error.
@AaronW. oh sorry i forgot it!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.