Help Center/ GaussDB/ Developer Guide(Centralized_2.x)/ Importing Data/ Deep Copy/ Performing a Deep Copy by Using the CREATE TABLE LIKE Statement
Updated on 2023-10-23 GMT+08:00

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

  1. 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);
    

  2. 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);
    

  3. Delete the original table.

    1
    openGauss=# DROP TABLE customer_t;
    

  4. 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;