I have two tables which are connected by relations on few columns. I wanna create foreign key that will take care of cleaning connected entities but not by deleting them - I need to use "SET NULL" option.
My tables:
CREATE TABLE resource
(
id integer NOT NULL,
project_id integer NOT NULL,
lang character(2) NOT NULL,
recource_id integer,
reserved_by integer NOT NULL,
CONSTRAINT resource_v0_pkey PRIMARY KEY (id, project_id, lang);
CREATE TABLE resource_list
(
id integer NOT NULL
project_id integer NOT NULL,
lang character(2) NOT NULL,
name character varying(128),
CONSTRAINT resource_list_v0_pkey PRIMARY KEY (id, project_id, lang);
);
How can I add following FK to set recource_id to BULL when resource is deleted. It should look something like that:
ALTER TABLE resource
ADD CONSTRAINT $2
FOREIGN KEY (resource_id, project_id, lang)
REFERENCES resource_list(id, project_id, lang)
ON DELETE SET NULL;
What is important I want set NULL only to resource.recource_id not for all connected fields. Is it possible?