Re: Discussion wanted: 'Trigger on Delete' cascade.

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: "Postgres General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Discussion wanted: 'Trigger on Delete' cascade.
Date: 2004-07-28 11:24:51
Message-ID: opsbuhzpp3cq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Display all headersTo: "R.Welz" <linuxprodukte(at)gmx(dot)de>
Subject: Re: [GENERAL] Discussion wanted: 'Trigger on Delete' cascade.
Date: Wed, 28 Jul 2004 13:24:26 +0200
From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
Organization: La Boutique Numérique

From what you say, your do not need a link table.
A link table is useful to link several items of a table to several items
of another table (many-to-
many relationship).

Example : items and categories.

1- An item belongs to a category
No need for a link table.
table categories ( id serial primary key );
table items ( category_id integer references categories( id ) on delete
cascade );

1- An item belongs to several categories
table categories ( id serial primary key );
table items ( id serial primary key );
table links (
category_id integer references categories( id ) on delete cascade,
item_id integer references items( id ) on delete cascade,
);
In this case you do need a link table.

You also need triggers to delete items when
- a link is deleted from the links table
- no more links to this item exist
which is, in fact, reference counting.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message val 2004-07-28 11:31:00 Indexes on Character Types
Previous Message Jim Seymour 2004-07-28 11:23:43 Re: no value fetch