数据库
首页 > 数据库> > postgresql 添加列主键自增

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,name,seq,tableName,nid,alter,table,主键
来源: https://www.cnblogs.com/412013cl/p/15724710.html