Re: Foreign key reference counting strategy?

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Subject: Re: Foreign key reference counting strategy?
Date: 2006-10-14 13:52:04
Message-ID: 4530EB84.4050904@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message chrisj 2006-10-14 21:42:39 Re: Assigning a timestamp without timezone to a timestamp
Previous Message Joost Kraaijeveld 2006-10-14 12:25:41 Foreign key reference counting strategy?