RENAME TABLE changes the name of one or more tables in a single, atomic operation.
RENAME TABLE instantly changes a table’s name without copying data. When multiple tables are listed, the operation is atomic—either all names change or none.
Issue RENAME TABLE old_name TO new_name;. The statement requires ALTER privilege on the table and CREATE, DROP on the database.
RENAME TABLE Customers TO Clients;
Chain pairs with commas: RENAME TABLE t1 TO t1_old, t2 TO t2_old;. If any pair fails, MariaDB rolls back all changes.
RENAME TABLE Orders TO Orders_2023, OrderItems TO OrderItems_2023;
Yes. Prefix the new name with the target schema: RENAME TABLE shop.Orders TO archive.Orders_2023;. The table’s definition and data relocate.
Constraints automatically update. Views, triggers, and stored procedures using the old name break; refresh or alter them after the rename.
Create a backup beforehand, schedule during low-traffic windows, and update application code via feature flags to avoid runtime errors.
Yes, an exclusive metadata lock is taken but usually released in milliseconds because no data is copied.
For InnoDB tables, all listed renames succeed or fail together, ensuring consistency.
You can run RENAME TABLE new_name TO old_name; as long as the original name is still free.