Re: Foreign key reference counting strategy? - Mailing list pgsql-sql

From Markus Schaber
Subject Re: Foreign key reference counting strategy?
Date
Msg-id 4530EB84.4050904@logix-tt.com
Whole thread Raw
In response to Foreign key reference counting strategy?  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
Responses Re: Foreign key reference counting strategy?  (Michael Fuhr <mike@fuhr.org>)
List pgsql-sql
Hi, Joost,

Joost Kraaijeveld wrote:

> Is there a strategy to implement reference counting for foreign keys so
> that if the last reference to the key is deleted, the record is deleted
> also?

Create an "after delete" trigger on the referencing table that checks
whether there still are records with the same key (IF EXISTS()), and
deletes the referenced row otherwise.

It won't hurt to have an index on the referencing column, for speed reasons.

HTH,
Markus
-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org


pgsql-sql by date:

Previous
From: Joost Kraaijeveld
Date:
Subject: Foreign key reference counting strategy?
Next
From: chrisj
Date:
Subject: Re: Assigning a timestamp without timezone to a timestamp