postgresql设置主键自增

法一:

CREATE TABLE banners  
(  
  id SERIAL primary key ,  
  name character varying,  
)  

 法二:

CREATE SEQUENCE banners_id_seq  
START WITH 1  
INCREMENT BY 1  
NO MINVALUE  
NO MAXVALUE  
CACHE 1;  
  
alter table banners alter column id setdefault nextval('banners_id_seq');

posted on 2020-01-07 16:28  不要挡着我晒太阳  阅读(1814)  评论(0编辑  收藏  举报

导航