MySQL swap table names for 2 sheets

Source: Internet
Author: User

In MySQL, how to complete the swap of 2 tables, such as T1 and T2 table name Swap, really just mutual rename so simple?

Note that we want to complete 2 tables at the same time, otherwise it will cause data write failure, so we need to lock the table before switching, while locking 2 tables, and then modify the name of the table:

LOCK TABLES T1 Write, T2 write;

ALTER TABLE T1 RENAME to T3;

ALTER TABLE T2 RENAME to T1;

ALTER TABLE T3 RENAME to T2;

UNLOCK TABLES;

This will be OK.



More wonderful MySQL Learning resources, in my win the workplace!

http://www.wyzc.com/mysql/?tg=LXUK--Zkf&tg=3006123630


MySQL swap table names for 2 sheets

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.