MySQL - RENAME TABLE
How can we use the RENAME TABLE statement?
RENAME TABLE customer to customer2;
RENAME TABLE backup_customer TO customer, backup_vendor TO vendor, backup_products TO product;
RENAME TABLE has an advantage over ALTER TABLE in that it can perform multiple table renames in a single operation. One use for this feature is to swap the names of two tables:
RENAME TABLE t1 TO tmp, t2 TO t1, tmp to t2;
For TEMPORARY tables, RENAME TABLE does not work. You must use ALTER TABLE instead.
How can we swap tables using the RENAME TABLE statement?
RENAME TABLE
db.table1 to olddb.table1, /* back up the current table */
newdb.table1 to db.table1 /* rename the new table as the old one */
page revision: 2, last edited: 06 May 2017 16:07