postgresql 添加列主键自增

1.对已存在的表添加列 和注释

alter table tableName add COLUMN columnName varchar(50);
comment on column tableName.columnName is '注释';

2.对已存在的列设置主键

ALTER TABLE tableName ADD CONSTRAINT xxx_xxx_primary_pk PRIMARY KEY (列);

3.创建自增

DROP SEQUENCE IF EXISTS {table_name}_nid_seq;
CREATE SEQUENCE {table_name}_nid_seq
START WITH 1
INCREMENT BY 1 NO MINVALUE NO MAXVALUE
CACHE 1;
alter table trans.{table_name} alter column nid set default nextval('{table_name}_nid_seq');

  

上一篇:【Postgresql分布式---单节点多实例部署citus】


下一篇:【Python入门教程】第58篇 函数进阶之元组解包