更新时间:2024-12-10 GMT+08:00
CHANGE修改列
MySQL使用CHANGE关键字同时修改列名、列数据类型、设置非空约束。DSC工具迁移时会根据GaussDB(DWS)的特性进行相应适配。
输入示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
CREATE TABLE IF NOT EXISTS `runoob_alter_test`( `dataType0` varchar(128), `dataType1` bigint, `dataType2` bigint, `dataType3` bigint, `dataType4` bigint )ENGINE=InnoDB DEFAULT CHARSET=utf8; ## A. ALTER TABLE runoob_alter_test CHANGE dataType1 dataType1New VARCHAR(50); ## B. ALTER TABLE runoob_alter_test CHANGE dataType2 dataType2New VARCHAR(50) NOT NULL; ## C. ALTER TABLE runoob_alter_test CHANGE dataType3 dataType3New VARCHAR(100) FIRST; ## D. ALTER TABLE runoob_alter_test CHANGE dataType4 dataType4New VARCHAR(50) AFTER dataType1; |
输出示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
CREATE TABLE "public"."runoob_alter_test" ( "datatype0" VARCHAR(512), "datatype1" BIGINT, "datatype2" BIGINT, "datatype3" BIGINT, "datatype4" BIGINT ) WITH ( ORIENTATION = ROW, COMPRESSION = NO ) NOCOMPRESS DISTRIBUTE BY HASH ("datatype0"); -- A. ALTER TABLE "public"."runoob_alter_test" CHANGE COLUMN "datatype1" "datatype1new" VARCHAR(200) NULL DEFAULT NULL; -- B. ALTER TABLE "public"."runoob_alter_test" CHANGE COLUMN "datatype2" "datatype2new" VARCHAR(200) NOT NULL; -- C. ALTER TABLE "public"."runoob_alter_test" CHANGE COLUMN "datatype3" "datatype3new" VARCHAR(400) NULL DEFAULT NULL; -- D. ALTER TABLE "public"."runoob_alter_test" CHANGE COLUMN "datatype4" "datatype4new" VARCHAR(200) NULL DEFAULT NULL; |
父主题: 表(可选参数、操作)