Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWILj-0000qP-8h for pgsql-novice@arkaria.postgresql.org; Tue, 13 Apr 2021 12:40:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lWILi-00058s-6M for pgsql-novice@arkaria.postgresql.org; Tue, 13 Apr 2021 12:40:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWILi-00058k-0A for pgsql-novice@lists.postgresql.org; Tue, 13 Apr 2021 12:40:58 +0000 Received: from smtp.hosts.co.uk ([85.233.160.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWILf-0004mR-B1 for pgsql-novice@postgresql.org; Tue, 13 Apr 2021 12:40:56 +0000 Received: from host86-150-235-122.range86-150.btcentralplus.com ([86.150.235.122] helo=E6540Wired) by smtp.hosts.co.uk with esmtpa (Exim) (envelope-from ) id 1lWILc-0001tJ-DG for pgsql-novice@postgresql.org; Tue, 13 Apr 2021 13:40:52 +0100 Message-ID: Subject: Advice on foreign key and cascading delete design - postgresql 12.6 From: "Steve Tucknott (TuSol)" Reply-To: steve@tusol.co.uk To: PostGreSQL Organization: TuSol Content-Type: multipart/alternative; boundary="=-+hLGsMNvus7O8+b/hf0n" Date: Tue, 13 Apr 2021 13:40:51 +0100 MIME-Version: 1.0 User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-+hLGsMNvus7O8+b/hf0n Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit 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? OR have I got the structure all wrong anyway and is there a cleaner way of holding, say notes, for records on a whole range of tables? Thanks all. --=-+hLGsMNvus7O8+b/hf0n Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit
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?

OR have I got the structure all wrong anyway and is there a cleaner way of holding, say notes, for records on a whole range of tables?

Thanks all.
--=-+hLGsMNvus7O8+b/hf0n--