MySQL Rename Table statement

Source: Internet
Author: User

Mysql Command rename table syntax

Rename table tbl_name TO new_tbl_name [, tbl_name2
New_tbl_name2,...]
Renaming is performed in atomic mode (atomically), which means that the table cannot be modified by any other thread when the renaming is running. 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;
Rename is executed from left to right, which means that if you want to swap two table names, you have to do this:

Rename table old_table TO backup_table,
New_table TO old_table,
Backup_table TO new_table;
As long as the two databases are on the same disk, you can change the name of one database to another:

Rename table current_db.tbl_name TO other_db.tbl_name;
When you execute RENAME, you cannot have any locked table or activity transactions. You must also have the ALTER and DROP permissions for the original table and the CREATE and INSERT permissions for the new table.

If MySQL encounters any error in renaming multiple tables, it will rename all renamed tables and return everything to the initial state.

Rename table is added to 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.