Performing a Deep Copy by Using the CREATE TABLE LIKE Statement
Run the CREATE TABLE LIKE statement to create a copy of the original table, batch insert data of the original table into the copy, and rename the copy to the name of the original table. This method does not inherit the primary key attributes of the original table. You can use the ALTER TABLE statement to add them.
Procedure
- Run the CREATE TABLE LIKE statement to create the copy customer_t_copy of the customer_t table.
1
openGauss=# CREATE TABLE customer_t_copy (LIKE customer_t);
- Run the INSERT INTO...SELECT statement to batch insert data of the original table into the copy.
1
openGauss=# INSERT INTO customer_t_copy (SELECT * FROM customer_t);
- Delete the original table.
1
openGauss=# DROP TABLE customer_t;
- Run the ALTER TABLE statement to rename the copy to the name of the original table.
1
openGauss=# ALTER TABLE customer_t_copy RENAME TO customer_t;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot