美文网首页
postgres 创建自增序列

postgres 创建自增序列

作者: ifree321 | 来源:发表于2020-08-26 14:08 被阅读0次
  1. 建表时添加自增序列和主键
CREATE TABLE users
(
id SERIAL primary key ,
  "admin_id" int4,
  "acc_id" int4,
);

ALTER TABLE "public"."im_group_kick_out_record" 
  OWNER TO "postgres";
  1. 给已有表增加自增序列

ALTER TABLE "public"."im_group_kick_out_record" 
  OWNER TO "postgres";


CREATE SEQUENCE im_group_kick_out_record_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
 
alter table im_group_kick_out_record alter column id set default nextval('im_group_kick_out_record_id_seq');

相关文章

网友评论

      本文标题:postgres 创建自增序列

      本文链接:https://www.haomeiwen.com/subject/isgxsktx.html