How to set the primary key self-increment when creating a table in a postgresql database using navicat?

clipboard.png

clipboard.png
No place was found.

Mar.16,2021

there is an auto_increment self-increment field in MySQL. PostgreSQL does not have a self-increment field, but there is a separate object: sequence. You can use sequences or other methods to implement such syntax. Or set the default value of a column to the value of sequence

set nextval ('products_product_no_seq') in the field default value.
create sequence see https://www.postgresql.org/do.

CREATE SEQUENCE products_product_no_seq START 101;
CREATE TABLE products (
    product_no integer DEFAULT nextval('products_product_no_seq'),
    ...
);

The

field type can be manually entered serial or serial8 . A sequence of table name _ field name _ seq is automatically created

Manual masturbation code can customize the seq name. Just the sauce.


clipboard.png

Menu