:: DEVELOPER ZONE
RENAME TABLEtbl_nameTOnew_tbl_name[,tbl_name2TOnew_tbl_name2] ...
This statement renames one or more tables. It was added in MySQL 3.23.23.
The rename operation is done atomically, which means that no other
thread can access any of the tables while the rename is running. For
example, if you have an existing table old_table,
you can create another table new_table that has
the same structure but is empty, and then replace the existing table
with the empty one as follows:
CREATE TABLEnew_table(...); RENAME TABLEold_tableTObackup_table,new_tableTOold_table;
If the statement renames more than one table, renaming operations
are done from left to right. If you want to swap two table names,
you can do so like this (assuming that no table named
tmp_table currently exists):
RENAME TABLEold_tableTOtmp_table,new_tableTOold_table,tmp_tableTOnew_table;
As long as two databases are on the same filesystem you can also rename a table to move it from one database to another:
RENAME TABLEcurrent_db.tbl_nameTOother_db.tbl_name;
When you execute RENAME, you can't have any
locked tables or active transactions. You must also have the
ALTER and DROP privileges on
the original table, and the CREATE and
INSERT privileges on the new table.
If MySQL encounters any errors in a multiple-table rename, it does a reverse rename for all renamed tables to get everything back to the original state.
© 1995-2005 MySQL AB. All rights reserved.

User Comments
Warning: query failed: Unknown column 'user.firstname' in 'field list' in /data0/sites/live/web-main/lib/mysql-cxn.php on line 69
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /data0/sites/live/web-main/lib/docbook.php on line 245
Add your own comment.