ON DELETE SET NULL in postgres

HI I am new to postgresql, so I lost some time. I want to save my data when deleting the parent. I want to know how to do "ON DELETE SET NULL" for the postgresql database. Please give me the key.

+7
postgresql entity-framework
source share
1 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, be sure to include the PostgreSQL version and explain what you have already tried.

+14
source share

All Articles