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.

    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.

    INSERT INTO customer_t_copy (SELECT * FROM customer_t);
    
  3. Delete the original table.

    DROP TABLE customer_t;
    
  4. Run the ALTER TABLE statement to rename the copy to the name of the original table.

    ALTER TABLE customer_t_copy RENAME TO customer_t;
    
Feedback
编组 3备份
    openGauss 2024-05-05 00:44:49
    cancel