PostgreSQL如何为主键创建自增序列(Sequences)

CREATE SEQUENCE public.user_role_id_seq

    INCREMENT 1

    START 1

    MINVALUE 1

    MAXVALUE 9223372036854775807

    CACHE 1;

ALTER SEQUENCE public.user_role_id_seq

    OWNER TO postgres;


CREATE TABLE public.user_role

(

    id integer NOT NULL DEFAULT nextval('user_role_id_seq'::regclass),

    type character varying(50) COLLATE pg_catalog."default" NOT NULL,

    CONSTRAINT user_role_pkey PRIMARY KEY (id),

    CONSTRAINT user_role_type_key UNIQUE (type)

)

WITH (

    OIDS = FALSE

)

TABLESPACE pg_default;

ALTER TABLE public.user_role

    OWNER to postgres;

COMMENT ON TABLE public.user_role

    IS 'user role table';

COMMENT ON COLUMN public.user_role.id

    IS 'unique id for user id';

你可能感兴趣的:(PostgreSQL如何为主键创建自增序列(Sequences))