I'm analyzing a following PostgreSQL schema:
CREATE SEQUENCE ref_email_type_ref_email_type_id_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
CREATE TABLE ref_email_type
(
ref_email_type_id integer NOT NULL DEFAULT nextval('ref_email_type_ref_email_type_id_seq'::regclass),
description character varying(50) NOT NULL,
CONSTRAINT ref_email_type_pkey PRIMARY KEY (ref_email_type_id)
)
CREATE TABLE email
(
email_id integer NOT NULL DEFAULT nextval('email_email_id_seq'::regclass),
ref_email_type_id integer NOT NULL DEFAULT nextval('email_ref_email_type_id_seq'::regclass),
email_address character varying(100),
CONSTRAINT email_pkey PRIMARY KEY (email_id),
CONSTRAINT email_ref_email_type_id_fkey FOREIGN KEY (ref_email_type_id)
REFERENCES ref_email_type (ref_email_type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
Does it make any sense to have email.ref_email_type_id declared with DEFAULT nextval('email_ref_email_type_id_seq'::regclass) in case of NOT NULL and existing constraint:
CONSTRAINT email_ref_email_type_id_fkey FOREIGN KEY (ref_email_type_id)
REFERENCES ref_email_type (ref_email_type_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
nextval()always executed atomically, and never rolled back (thus always provides a unique value, but usually with gaps in the table).