当前位置:数据库 > SQLServer >>

postgresql如何让主键自增

postgresql如何让主键自增
 
法一:
Sql代码  
CREATE TABLE customers  
(  
  customerid SERIAL primary key ,  
  companyname character varying,  
  contactname character varying,  
  phone character varying,  
  country character varying  
)  

 

 法二:
Sql代码  
CREATE SEQUENCE event_id_seq  
START WITH 1  
INCREMENT BY 1  
NO MINVALUE  
NO MAXVALUE  
CACHE 1;  
  
alter table event alter column id set default nextval('event_id_seq');  

 

 
2种方法都可以,第一种简单点。
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,