postgres 创建自增序列

  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 创建自增序列)