Performing a Deep Copy by Using the CREATE TABLE Statement
Run the CREATE TABLE 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.
When creating the copy, you can specify table and column attributes, such as the primary key.
Procedure
Perform the following operations to carry out a deep copy for the customer_t table:
- Run the CREATE TABLE statement to create the copy customer_t_copy of the customer_t table.
1 2 3 4 5 6
openGauss=# CREATE TABLE customer_t_copy ( c_customer_sk integer, c_customer_id char(5), c_first_name char(6), c_last_name char(8) ) ;
- 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