Multiple foreign keys - Mailing list pgsql-novice

From Prokopis Prokopidis
Subject Multiple foreign keys
Date
Msg-id 3E30F86E.6050103@ilsp.gr
Whole thread Raw
Responses Re: Multiple foreign keys
List 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.


pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: Long time Vacuum full
Next
From: Rory Campbell-Lange
Date:
Subject: Re: Learning Plpgsql ??