Multiple foreign keys

From: Prokopis Prokopidis <prokopis(at)ilsp(dot)gr>
To: pgsql-novice(at)postgresql(dot)org
Subject: Multiple foreign keys
Date: 2003-01-24 08:25:18
Message-ID: 3E30F86E.6050103@ilsp.gr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I've just started playing with SQL and postgres, and I have a question
about multiple foreign keys.

Let's say we have three tables "student", "teacher" and "staff", plus a
table "comment" with attributes like "date" and "text". We want zero or
N comments to be associated with each row of the other three tables.

I was thinking of creating three foreign keys in the "comment" table,
say "fk_student", "fk_teacher" and "fk_staff". Now, is there a way to
impose a constraint that a comment row must have one and only one NOT
NULL fk value?

If this is not the correct way to solve the problem, what alternative
solutions are there?

Best,

P.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2003-01-24 10:32:09 Re: Multiple foreign keys
Previous Message Tom Lane 2003-01-24 05:38:17 Re: Long time Vacuum full