Re: [SQL] simple addition of constraints problem

Поиск
Список
Период
Сортировка
От Richard Poole
Тема Re: [SQL] simple addition of constraints problem
Дата
Msg-id 20040608225550.GA26592@guests.deus.net
обсуждение исходный текст
Список pgsql-general
On Tue, Jun 08, 2004 at 05:51:22PM -0400, Michelle Murrain wrote:

> I'd like to make 'courseid' in this second table a foreign key,
> referencing 'courseid' in the first table. So I did this command:
>
> charter_dev2=# ALTER TABLE coursesevaluations ADD CONSTRAINT rc_ce
> FOREIGN KEY (courseid) REFERENCES rcourseinfo (courseid);
>
> And I get this result:
>
> NOTICE:  ALTER TABLE will create implicit trigger(s) for FOREIGN KEY
> check(s)
> ERROR:  rc_ce referential integrity violation - key referenced from
> coursesevaluations not found in rcourseinfo

What this is telling you is not that there is any problem with your
formulation of the constraint (which as far as I can tell is what you
want), but that the existing data in the tables violates the constraint
you're trying to impose. If you do something like

SELECT rcoursesevaluations.courseid
FROM rcoursesevalutations NATURAL LEFT JOIN rcourseinfo
WHERE rcourseinfo.courseid IS NULL

you should see which courseids appear in rcoursesevaluations but not in
rcourseinfo.


Richard

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

Предыдущее
От: CSN
Дата:
Сообщение: using regexp backreferences
Следующее
От: DeJuan Jackson
Дата:
Сообщение: Re: using regexp backreferences