constraint

ON DELETE SET NULL

Replaces the referencing value with NULL; the column must permit NULL. Target: PostgreSQL 17; focused syntax.

Formal Syntax & Structure

sql syntaxsql
REFERENCES parent(id) ON DELETE SET NULL

Working Example

Example Snippetsql
CREATE TABLE parent(id INT PRIMARY KEY NOT NULL); CREATE TABLE child(parent_id INT DEFAULT 0 REFERENCES parent(id) ON DELETE SET NULL); INSERT INTO parent VALUES (0),(1); INSERT INTO child VALUES (1);DELETE FROM parent WHERE id=1;SELECT parent_id FROM child;
SQL Reference