Re: Advice on foreign key and cascading delete design - postgresql 12.6

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: steve@tusol.co.uk
Cc: PostGreSQL <pgsql-novice@postgresql.org>
Date: 2021-04-13T14:47:18Z
Lists: pgsql-novice
"Steve Tucknott (TuSol)" <steve@tusol.co.uk> writes:
> I have a few tables that are subservient to multiple other tables
> (notes, addresses, attached documents etc).
> These tables carry the 'owning' table name and its record's PK.

> I can manually keep these tables tidy and avoid orphans, but is there a
> way within postgresql to reference these tables on a FK constraint to
> automatically delete the subservient recs when the parent is deleted?

Maybe I'm missing something, but aren't you just looking for the
ON DELETE CASCADE option of foreign key constraints?

			regards, tom lane