数据仓库服务 GAUSSDB(DWS)-LIKE 表克隆

时间:2024-12-10 11:28:50

LIKE 表克隆

MySQL数据库中,可以使用CREATE TABLE .. LIKE ..方式克隆旧表结构创建新表。 GaussDB (DWS)也支持这种建表方式。DSC工具迁移时会添加额外的表属性信息。

输入示例

1
2
3
4
5
6
7
8
CREATE TABLE IF NOT EXISTS `public`.`runoob_tbl_old`(
    `dataType_1` YEAR,
    `dataType_2` YEAR(4),
    `dataType_3` YEAR DEFAULT '2018',
    `dataType_4` TIME DEFAULT NULL
);

CREATE TABLE `runoob_tbl` (like `runoob_tbl_old`);

输出示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
CREATE TABLE IF NOT EXISTS "public"."runoob_tbl_old"
(
  "datatype_1" SMALLINT,
  "datatype_2" SMALLINT,
  "datatype_3" SMALLINT DEFAULT '2018',
  "datatype_4" TIME WITHOUT TIME ZONE DEFAULT NULL
)
  WITH ( ORIENTATION = ROW, COMPRESSION = NO )
  NOCOMPRESS
  DISTRIBUTE BY HASH ("datatype_1");

CREATE TABLE "public"."runoob_tbl"( LIKE "public"."runoob_tbl_old"
   INCLUDING COMMENTS INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES INCLUDING STORAGE);
support.huaweicloud.com/tg-dws/dws_16_0157.html