The IF EXISTS  clause prevents an error from occurring for views that don’t exist. When this clause is given, a NOTE  is generated for each nonexistent view. See Section 13.7.7.42, “SHOW WARNINGS Statement” . 

## 13.1.36 RENAME TABLE Statement 

RESTRICT  and CASCADE , if given, are parsed and ignored. 

RENAME TABLE tbl_name  TO new_tbl_name [, tbl_name2  TO new_tbl_name2 ] ... 

RENAME TABLE  renames one or more tables. You must have ALTER  and DROP  privileges for the original table, and CREATE  and INSERT  privileges for the new table. 

For example, to rename a table named old_table  to new_table , use this statement: 

RENAME TABLE old_table TO new_table; 

That statement is equivalent to the following ALTER TABLE  statement: 

ALTER TABLE old_table RENAME new_table; 

RENAME TABLE , unlike ALTER TABLE , can rename multiple tables within a single statement: 

RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2, old_table3 TO new_table3; 

Renaming operations are performed left to right. Thus, to swap two table names, do this (assuming that a table with the intermediary name tmp_table  does not already exist): 

RENAME TABLE old_table TO tmp_table, new_table TO old_table, tmp_table TO new_table; 

Metadata locks on tables are acquired in name order, which in some cases can make a difference in operation outcome when multiple transactions execute concurrently. See Section 8.11.4, “Metadata Locking” . 

As of MySQL 8.0.13, you can rename tables locked with a LOCK TABLES  statement, provided that they are locked with a WRITE  lock or are the product of renaming WRITE -locked tables from earlier steps in a multiple-table rename operation. For example, this is permitted: 

LOCK TABLE old_table1 WRITE; RENAME TABLE old_table1 TO new_table1, new_table1 TO new_table2; 

This is not permitted: 

LOCK TABLE old_table1 READ; RENAME TABLE old_table1 TO new_table1, new_table1 TO new_table2; 

Prior to MySQL 8.0.13, to execute RENAME TABLE , there must be no tables locked with LOCK TABLES . 

With the transaction table locking conditions satisfied, the rename operation is done atomically; no other session can access any of the tables while the rename is in progress. 

If any errors occur during a RENAME TABLE , the statement fails and no changes are made. 

