nhuynh105
nhuynh105

Reputation: 21

ORA-00942 parent key not found

create table Researcher
  (Pid number(7),
   lname varchar2(12),
   fname char(10),
   constraint pkResearcher PRIMARY KEY(Pid));

create table Project
  (ProjId char(10),
   MedicName varchar2(10),
   Purpose varchar2(12),
   Start_date date,
   End_date date,
   PI_Id number (7),
   constraint pkProject PRIMARY KEY(ProjId),
   constraint fkProject FOREIGN KEY (PI_Id) references Researcher);

I've recently started learning sql.

I previously inserted a statement:

insert into Project
values ('PR001','Medic1','heart','1-SEP-2017','31-JUL-2019','10001');

This statement was created but when I tried my next statement:

insert into Project
values ('PR005','Medic5','blood','10-JUL-18','31-JAN-20','10102');

I encounter the error integrity constraint (FKPROJECT) violated - parent key not found

Upvotes: 0

Views: 52

Answers (1)

Popeye
Popeye

Reputation: 35900

It simply means that the pid 10102 is not present in the table Researcher which is defined via constraint fkProject.

Insert valid record in the Researcher table having pid=10102 and everything will work fine.

Cheers!!

Upvotes: 1

Related Questions