Re: Multiple foreign keys

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: Multiple foreign keys
Дата
Msg-id 1043407400.3079.41.camel@linda.lfix.co.uk
обсуждение исходный текст
Ответ на Re: Multiple foreign keys  (Prokopis Prokopidis <prokopis@ilsp.gr>)
Список 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.Elphick@lfix.co.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


В списке pgsql-novice по дате отправления:

Предыдущее
От: Oliver Elphick
Дата:
Сообщение: Re: Stored Procedure Question
Следующее
От: Luis Miedzinski
Дата:
Сообщение: from mssql7.0 and ASP to postgres and PHP