constraint

ON DELETE CASCADE

Deletes dependent rows automatically. Review deletion scope before using this action. Target: PostgreSQL 17; focused syntax.

Formal Syntax & Structure

sql syntaxsql
REFERENCES parent(id) ON DELETE CASCADE

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 CASCADE); INSERT INTO parent VALUES (0),(1); INSERT INTO child VALUES (1);DELETE FROM parent WHERE id=1;SELECT parent_id FROM child;
SQL Reference