Updated on 2024-07-19 GMT+08:00

RENAME (Table Renaming)

The statement for renaming a table in MySQL is slightly different from that in GaussDB(DWS). DSC will perform adaptation based on GaussDB(DWS) features during migration.

Currently, DSC does not support original table names prefixed with DATABASE/SCHEMA.

  1. MySQL uses the RENAME TABLE statement to change a table name.

    Input

    1
    2
    3
    4
    5
    # Rename a single table. 
    RENAME TABLE DEPARTMENT TO NEWDEPT;
    
     # Rename multiple tables. 
    RENAME TABLE NEWDEPT TO NEWDEPT_02,PEOPLE TO PEOPLE_02;
    

    Output

    1
    2
    3
    4
    5
    6
    -- Rename a single table. 
    ALTER TABLE "public"."department" RENAME TO "newdept";
    
    -- Rename multiple tables. 
    ALTER TABLE "public"."newdept" RENAME TO "newdept_02";
    ALTER TABLE "public"."people" RENAME TO "people_02";
    
  2. In MySQL, the ALTER TABLE RENAME statement is used to change a table name. When this statement is migrated by DSC, the keyword AS is converted to TO.

    Input

    1
    2
    3
    4
    5
    ## A.
    ALTER TABLE runoob_alter_test RENAME TO runoob_alter_testnew;
    
    ## B.
    ALTER TABLE runoob_alter_testnew RENAME AS runoob_alter_testnewnew;
    

    Output

    1
    2
    3
    4
    5
    -- A.
    ALTER TABLE "public"."runoob_alter_test" RENAME TO "runoob_alter_testnew";
    
    -- B.
    ALTER TABLE "public"."runoob_alter_testnew" RENAME TO "runoob_alter_testnewnew";