修改表结构 添加外键 plaintext teledb create table tp(f1 int not null,f2 int ,primary key(f1)); CREATE TABLE teledb create table tf(f1 int not null,f2 int ); CREATE TABLE teledb ALTER TABLE tf ADD CONSTRAINT tff1fkey FOREIGN KEY (f1) REFERENCES tp (f1); ALTER TABLE teledb d+ tf Table "public.tf" Column Type Collation Nullable Default Storage Stats target Description +++++++ f1 integer not null plain f2 integer plain Foreignkey constraints: "tff1fkey" FOREIGN KEY (f1) REFERENCES tp(f1) Distribute By: SHARD(f1) Location Nodes: ALL DATANODES 外键使用限制: 外键只是同一个节点内约束有效果,所以外键字段和对应主键字段必需都是表的分布键,否则由于数据分布于不同的节点内会导致更新失败。 分区表和冷热分区表也不支持外键,数据分区后位于不同的物理文件中,无法约束。 删除外键 plaintext teledb ALTER TABLE tf DROP CONSTRAINT tff1fkey; ALTER TABLE 修改表所属模式 plaintext teledb create schema teledb; CREATE SCHEMA teledb dt t List of relations Schema Name Type Owner +++ public t table teledb (1 row) teledb alter table t set schema teledb; ALTER TABLE teledb dt t List of relations Schema Name Type Owner +++ teledb t table teledb (1 row) 修改表所属用户 plaintext teledb dt t List of relations Schema Name Type Owner +++ teledb t table teledb (1 row) teledb