ON DELETE SET NULL in postgres

entity-framework postgresql

Question

HI I'm new to postgresql environment so been lost for a while. I want to keep my data when parent entity is deleted. I want to know how to make 'ON DELETE SET NULL' for postgresql database. Please give me a clue.

1
18
11/11/2013 3:16:11 AM

Popular Answer

ON DELETE SET NULL is a standard foreign key constraint option.

CREATE TABLE some_child (
    parent_id integer references parent(id) on delete set null
);

or:

ALTER TABLE some_child 
ADD CONSTRAINT parent_id_fk 
FOREIGN KEY (parent_id) REFERENCES parent(id) 
ON DELETE SET NULL;

See the documentation.

In future posts make sure you include your PostgreSQL version and explain what you've already tried.

30
8/20/2017 4:27:13 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow