Re: Multiple foreign keys

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Prokopis Prokopidis <prokopis(at)ilsp(dot)gr>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Multiple foreign keys
Date: 2003-01-24 11:23:21
Message-ID: 1043407400.3079.41.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Fri, 2003-01-24 at 10:54, Prokopis Prokopidis wrote:
> Yes, but "3 tables" was just an example. What if I have 10 or 1000
> tables that need a comment? This CHECK solution becomes "ugly" very
> quickly. There must be another way ...

In that case, create a new table fkeys, for example:

create table fkeys (
id text primary key,
table TEXT NOT NULL
};

Then each id in students, teachers, etc. has a foreign key reference to
fkeys and each comment similarly has a foreign key on fkeys.

You would need to add your own triggers to drop items from fkeys when
they are deleted from the other tables.

The ideal would be to use inheritance and have a direct fk reference
from comments to the parent table, but that won't work at the moment.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"If anyone has material possessions and sees his
brother in need but has no pity on him, how can the
love of God be in him?"
I John 3:17

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Luis Miedzinski 2003-01-24 11:56:46 from mssql7.0 and ASP to postgres and PHP
Previous Message Oliver Elphick 2003-01-24 10:56:02 Re: Stored Procedure Question