MySQL command rename tables rename table syntax

Source: Internet
Author: User

MySQL command rename tables rename table syntax

RENAME TABLE tbl_name to new_tbl_name[, tbl_name2 to
New_tbl_name2,...]
Renaming is performed atomically (atomically), which means that when the name change is running, no other thread can be the table. This makes it possible to replace a table with an empty table.

CREATE TABLE new_table (...);
RENAME TABLE old_table to Backup_table, new_table to old_table;
Renaming is performed from left to right, which means that if you want to swap two of table names, you have to:

RENAME TABLE old_table to Backup_table,
New_table to Old_table,
Backup_table to New_table;
As long as two databases are on the same disk, you can also rename from one database to another:

RENAME TABLE current_db.tbl_name to Other_db.tbl_name;
When you perform RENAME, you cannot have any locked tables or active transactions. You must also have ALTER and DROP permissions on the original table, as well as CREATE and INSERT permissions on the new table.

If MySQL encounters any errors in multiple table renaming, it will reverse the renaming of all renamed tables and return everything to its original state.

RENAME TABLE is added to the MySQL 3.23.23.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.