Subject Re: problem adding foreign key
Author Adam
My guess is that you have some "contacts" records without a parent
record in the customer table. What does this query return?

select *
from contacts
where customerid not in
(select id from customer);

You are allowed to have more than one table with a foreign key to the
same parent field, so that won't be it.


Adam


--- In firebird-support@yahoogroups.com, "markd_mms" <spam@m...>
wrote:
>
>
> hi. i'm pretty new to firebird and sql so i'm not sure if i'm
making a
> stupid mistake...
>
> i have 2 tables, contacts and customers. customers has a pk called
ID
> and contacts has a field (with no contraints) called CustomerID.
>
> when i execute the following sql i get an error...
>
> alter table CONTACTS
> add constraint FK_CONTACTS_CUSTOMERS
> foreign key ("CustomerID")
> references CUSTOMERS(ID)
> on delete CASCADE
> on update CASCADE
>
> and the error is...
>
> violation of FOREIGN KEY constraint "PK_CUSTOMERS" on
table "CUSTOMERS"
>
> there is another table with a foreign key on Customers.ID. i'm not
> sure if this makes a difference.
>
> running v1.5.2.4731
>
> any ideas?
>
> TIA