Re: Foreign Key constraint help!

From: Ralf Niendorf <Ralf.Niendorf_at_brr.de>
Date: Mon, 21 Dec 1998 11:59:45 +0100
Message-ID: <367E2A21.BA499AA5_at_brr.de>


Hi Andrea,
if you have created both primary keys, it should work. Are your tables empty or is there data in? You get an error ora-02298, if you try to create the foreign key and you have entries in table2 without parent data in table1. Maybe your ORA-error is related to this problem.

Dan Hield wrote:
>
> Yes, I have created the primary keys on both tables sucessfully, hence 'not
> null' values in table description. This is why it puzzles me.
>
> Andrea Mattioli wrote in message <367BAA4C.965623FD_at_gedy.it>...
> >Have you defined the primary key on table1?
> >
> >Alter table table1 add primary key (col1,col2);
> >
> >Dan Hield wrote:
> >
> >> Using Oracle7, I am trying to create a foreign key on a table which has a
> >> composite key of three referencing another table which has a composite
> key
> >> of two.
> >>
> >> i.e.
> >> table1
> >> name Null? Type
> >> col1 not null varchar2(8)
> >> col2 not null varchar2(50)
> >> col3 varchar2(3)
> >> col4 number(3)
> >> col5 varchar2(2000)
> >>
> >> table2
> >> name Null? Type
> >> col1 not null varchar2(8)
> >> col2 not null varchar2(50)
> >> col3 not null varchar2(50)
> >>
> >> I get this error message: 'ORA-02294: cannot add referential constraint -
> >> paretn keys not found.'
> >>
> >> The script I am using to attemp to create the foreign key is as follows:
> >>
> >> ALTER TABLE2 ADD CONSTRAINT fk1
> >> FOREIGN KEY (col1, col2) REFERENCES TABLE1(col1, col2);
> >>
> >> Any help greatly appreciated. Keen to learn fast!
> >>
> >> Dan.
> >
Received on Mon Dec 21 1998 - 11:59:45 CET

Original text of this message