This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a command to swap the table in a MySQL Database.
Recently, I got a requirement like a swap or rename the table, it should execute in a lock/transaction. People can access the table before or after the swapping only.
In an ETL/Database work, we are creating a staging table for validation and later it requires to overwrite with an original table name.
Below is a simple command, which you can use for this task:
Here, DBRND_Original is an existing table and DBRND_Original_New is my staging table.
Now, I am swapping the table using one rename command which performs whole swapping operation in one transaction.
1 |
RENAME TABLE DBRND_Original TO DBRND_Original_Backup, DBRND_Original_New To DBRND_Original; |
Leave a Reply