GBase 8a
其他
文章

列新加注释或者修改原注释

发表于2025-01-02 14:27:4441次浏览3个评论

已经创建的表,不支持直接修改新增注释或者修改注释,如果要修改,建议两种办法,重建表,或者新建列-update数据-删除原列-新建列改名的折衷办法。

-- show create table test.lineorder 查看建表sql
CREATE TABLE "lineorder" (
 "lo_orderkey" bigint(20) DEFAULT NULL,
 "lo_linenumber" bigint(20) DEFAULT NULL,
 "lo_custkey" bigint(20) DEFAULT NULL,
 "lo_partkey" bigint(20) DEFAULT NULL,
 "lo_suppkey" bigint(20) DEFAULT NULL,
 "lo_orderdate" bigint(20) DEFAULT NULL,
 "lo_orderpriority" varchar(30) DEFAULT NULL,
 "lo_shippriority" bigint(20) DEFAULT NULL,
 "lo_quantity" bigint(20) DEFAULT NULL,
 "lo_extendedprice" bigint(20) DEFAULT NULL,
 "lo_ordtotalprice" bigint(20) DEFAULT NULL,
 "lo_discount" bigint(20) DEFAULT NULL,
 "lo_revenue" bigint(20) DEFAULT NULL,
 "lo_supplycost" bigint(20) DEFAULT NULL,
 "lo_tax" bigint(20) DEFAULT NULL,
 "lo_commitdate" bigint(20) DEFAULT NULL,
 "lo_shipmode" varchar(30) DEFAULT NULL
) ENGINE=EXPRESS DISTRIBUTED BY('lo_orderkey') DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace'

-- 以修改lo_tax为例
alter table test.lineorder  change lo_tax  lo_tax bigint(20) default null comment 'tax rate';
-- alter table 库名.表名 change 列名 新列名 列描述 comment '新注释';
-- 新列名可以与原列名一样。
-- 列描述必须写全,如果不写全,可能会执行报错。
-- 可用于新加注释或者修改原注释。

-- 修改后查看建表sql
CREATE TABLE "lineorder" (
 "lo_orderkey" bigint(20) DEFAULT NULL,
 "lo_linenumber" bigint(20) DEFAULT NULL,
 "lo_custkey" bigint(20) DEFAULT NULL,
 "lo_partkey" bigint(20) DEFAULT NULL,
 "lo_suppkey" bigint(20) DEFAULT NULL,
 "lo_orderdate" bigint(20) DEFAULT NULL,
 "lo_orderpriority" varchar(30) DEFAULT NULL,
 "lo_shippriority" bigint(20) DEFAULT NULL,
 "lo_quantity" bigint(20) DEFAULT NULL,
 "lo_extendedprice" bigint(20) DEFAULT NULL,
 "lo_ordtotalprice" bigint(20) DEFAULT NULL,
 "lo_discount" bigint(20) DEFAULT NULL,
 "lo_revenue" bigint(20) DEFAULT NULL,
 "lo_supplycost" bigint(20) DEFAULT NULL,
 "lo_tax" bigint(20) DEFAULT NULL COMMENT 'tax rate',
 "lo_commitdate" bigint(20) DEFAULT NULL,
 "lo_shipmode" varchar(30) DEFAULT NULL
) ENGINE=EXPRESS DISTRIBUTED BY('lo_orderkey') DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace'

评论

登录后才可以发表评论
崔哥发表于 2个月前
折戟沉沙铁未销,自将磨洗认前朝。东风不与周郎便,铜雀春深锁二乔。
曾云林发表于 2个月前
向大佬学习
曾浩轩发表于 2个月前
闪闪发光