postgresql如何讓主鍵自增

 

  1.  
    
    法一:
    
    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');  
    
相關文章
相關標籤/搜索