数据仓库服务 GAUSSDB(DWS)-ALTER TABLE:表操作示例

时间:2024-06-19 14:33:02

表操作示例

重命名表:

1
ALTER TABLE CUSTOMER RENAME TO CUSTOMER_t;

给表增加一个新的约束:

1
ALTER TABLE customer_address ADD PRIMARY KEY(ca_address_sk);

根据已有唯一索引为表增加主键约束或唯一约束。

先给表CUSTOMER创建唯一索引CUSTOMER_constraint1,然后根据已有唯一索引增加主键约束,并对前面创建的索引rename:

1
2
CREATE UNIQUE INDEX CUSTOMER_constraint1 ON CUSTOMER(C_CUSTKEY);
ALTER TABLE CUSTOMER ADD CONSTRAINT CUSTOMER_constraint2 PRIMARY KEY USING INDEX CUSTOMER_constraint1;

重命名表约束:

1
ALTER TABLE CUSTOMER RENAME CONSTRAINT CUSTOMER_constraint2 TO CUSTOMER_constraint;

删除表约束:

1
ALTER TABLE CUSTOMER DROP CONSTRAINT CUSTOMER_constraint;

给表增加一个索引:

1
ALTER TABLE CUSTOMER ADD INDEX CUSTOMER_index(C_CUSTKEY);

删除表索引:

1
2
ALTER TABLE CUSTOMER DROP INDEX CUSTOMER_index;
ALTER TABLE CUSTOMER DROP KEY CUSTOMER_index;

向在一个列存表中添加局部聚簇列:

1
ALTER TABLE customer_address ADD CONSTRAINT customer_address_cluster PARTIAL CLUSTER KEY(ca_address_sk);

删除一个列存表中的局部聚簇列:

1
ALTER TABLE customer_address DROP CONSTRAINT customer_address_cluster;

切换列存表的存储格式:

1
ALTER TABLE customer_address SET (COLVERSION = 1.0);

修改表的分布方式:

1
ALTER TABLE customer_address DISTRIBUTE BY REPLICATION;

修改表模式:

1
ALTER TABLE customer_address SET SCHEMA tpcds;

单表冷热切换:

1
ALTER TABLE cold_hot_table REFRESH STORAGE;

列存分区表修改为冷热表:

1
2
3
4
5
6
7
CREATE table test_1(id int,d_time date)
WITH(ORIENTATION=COLUMN)
DISTRIBUTE BY HASH (id)
PARTITION BY RANGE (d_time)
(PARTITION p1 START('2022-01-01') END('2022-01-31') EVERY(interval '1 day'))

ALTER TABLE test_1 SET (storage_policy = 'LMT:100');

修改表缓存策略(仅云原生3.0版本支持):

ALTER TABLE orders SET (cache_policy = 'NONE');
support.huaweicloud.com/devg-dws-v3/dws_16_0039.html