Re: Multiple foreign keys
От | Oliver Elphick |
---|---|
Тема | Re: Multiple foreign keys |
Дата | |
Msg-id | 1043404329.3068.9.camel@linda.lfix.co.uk обсуждение исходный текст |
Ответ на | Multiple foreign keys (Prokopis Prokopidis <prokopis@ilsp.gr>) |
Список | pgsql-novice |
On Fri, 2003-01-24 at 08:25, Prokopis Prokopidis wrote: > 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? Add this table constraint: CONSTRAINT "only one not null" CHECK ((fk_student IS NOT NULL AND fk_teacher IS NULL AND fk_student IS NULL) OR (fk_student IS NULL AND fk_teacher IS NOT NULL AND fk_student IS NULL) OR (fk_student IS NULL AND fk_teacher IS NULL AND fk_student IS NOT NULL) ) -- 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 по дате отправления: