Code:
-- Table: public.customers
CREATE TABLE public.customers (
customercd serial NOT NULL,
pass char(32) NOT NULL,
lnamek varchar(20) NOT NULL,
fnamek varchar(20) NOT NULL,
status boolean NOT NULL DEFAULT true,
/* Keys */
CONSTRAINT customers_pkey
PRIMARY KEY (customercd)
) WITHOUT OIDS;
CREATE INDEX customers_index01
ON public.customers
(customercd, status);
Code:
-- Table: public.customercontacts
CREATE TABLE public.customercontacts (
customercd integer NOT NULL,
contact varchar(50) NOT NULL,
"type" varchar(3),
/* Keys */
CONSTRAINT customercontacts_pkey
PRIMARY KEY (contact),
/* Foreign keys */
CONSTRAINT foreign_key01
FOREIGN KEY (customercd)
REFERENCES public.customers(customercd)
ON DELETE RESTRICT
ON UPDATE CASCADE
) WITHOUT OIDS;
-- no need to provide the customercd and status because auto-increment and with default value respectively.
2) insertCustomerC ontact(customercd, contact, type)
-- need to provide the all fields.
Problem: How can I determine the previously used customercd that generated by the serial field upon insertCustomer in order to pass the customercd as argument to insertCustomerC ontact.
Comment