postgresql create auto-increment field

Original text: https://blog.csdn.net/jinxiumeihappy/article/details/77978316

The first step is to create a sequence: the general sequence name is composed of the data table name + primary key field + seq (usually the primary key field is the self-incrementing field), the following table name is t_certificate, and the primary key field is c_certificateid 

 

Create a sequence statement as follows:

CREATE SEQUENCE t_certificate_c_certificateid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

 

The second step is to set the table field to auto-increment sql

alter table t_certificate alter column c_certificateid set default nextval('t_certificate_c_certificateid_seq');

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325073485&siteId=291194637