You can execute the RENAME TABLE statement to rename one or more tables.
RENAME TABLE tblname TO newtblname [, tb1name2 TO newtblname …] ;
The name of the original table.
The name of the new table.
tblname TO newtblname
[, tb1name2 TO newtblname …] ;
To rename multiple tables at a time, separate the table names with commas (,).
- After you execute the RENAME TABLE statement, the specified tables are automatically renamed. When the tables are being renamed, other threads cannot read data from the tables.
- If you execute this statement to rename multiple tables, the tables are renamed in the left-to-right order.
- To execute the RENAME TABLE statement, ensure that no tables are locked or involved in active transactions. To execute the RENAME TABLE statement, ensure that you have the ALTER and DROP permissions on the original table and the CREATE and INSERT permissions on the new table.
- You can execute the RENAME TABLE statement to rename views.
- Create tables t1 and t2.
create table t1(c1 int); create table t2(c1 int);
- Rename table t1 to t11.
rename table t1 to t11;
- Rename table t11 to t111 and table t2 to t22.
rename table t11 to t111, t2 to t22;
- Rename table t111 to t1111, and then rename table t1111 to t1.
rename table t111 to t1111, t1111 to t1;