Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a MySQL table using SQL statement

Tags:

sql

php

mysql

I want to rename an existing table using SQL statement:

I have already tried:

  1. mysql_query("RENAME '$renameFolder' TO '$newName'");
  2. mysql_query("ALTER TABLE '$renameFolder' RENAME TO '$newName'");
  3. mysql_query("RENAME TABLE '$renameFolder' TO '$newName'");

Using any of the 3 statements I'm always getting the same error message:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax"

Please tell me what I'm doing wrong!

like image 398
user1216858 Avatar asked Mar 03 '12 19:03

user1216858


1 Answers

Try using backquotes instead, e.g.:

mysql_query( "RENAME TABLE `" . $renameFolder . "` TO `" . $newname . "`" );
like image 104
Overv Avatar answered Oct 19 '22 23:10

Overv