ORA-02291: integrity constraint (NAVY10.SYS_C00317513) violated - parent key not found

5.1k Views Asked by At

I have to create tables and insert the data using INSERT SQL statements and SQL LOADER utility. I am using Oracle 10g. the following are the create table statements:

CREATE TABLE Employee_C (
    EID char(3), 
    Name varchar2(20), 
    Salary number(7,2), 
    MID char(3), 
    PRIMARY KEY (EID), 
    FOREIGN KEY (MID) REFERENCES Employee_C (EID)
);

CREATE TABLE Conference_C (
    ConfID char(6),
    Title varchar2(20), 
    Location varchar2(20), 
    Sdate date,  
    PRIMARY KEY (ConfID)
); 

CREATE TABLE Topic_C (
    Tnum char(3), 
    Title varchar2(20), 
    PRIMARY KEY (Tnum)
);

CREATE TABLE Includes_C (
    Tnum char(3), 
    ConfID char(6), 
    PRIMARY KEY (Tnum,ConfID), 
    FOREIGN KEY (Tnum) REFERENCES Topic_C, 
    FOREIGN KEY (ConfID) REFERENCES Conference_C
);

CREATE TABLE Deals_C (
    EID char(3), 
    ConfID char(6), 
    PRIMARY KEY (EID,ConfID), 
    FOREIGN KEY (EID) REFERENCES Employee_C, 
    FOREIGN KEY (ConfID) REFERENCES Conference_C
);

I used INSERT SQL statements to insert data into Topic_C table, and used sql loader utility to insert data into other 4 tables.

So my problem is when I run sql loader, I get the following error:

Record 1: Rejected - Error on table INCLUDES_C.
ORA-02291: integrity constraint (NAVY10.SYS_C00317513) violated - parent key not found

The other tables are working perfectly fine!

I don't know where I am going wrong, please clarify Thank You

1

There are 1 best solutions below

0
On BEST ANSWER

As @OMGPonies mentioned above, when you're loading records into Includes_C one or both of the following is happening:

  1. Includes_C.Tnum isn't in Topic_C
  2. Includes_C.ConfID isn't in Conference_C

The best approach would be to load the parent tables first, then work down through the children. To do that, just load the tables in the order you've defined them. If that doesn't work it means you truly do have a Tnum and/or ConfID value that violates the foreign key.