Site icon IT Tutorial

ORA-02291: integrity constraint (string.string) violated – parent key not found

I got ” ORA-02291: integrity constraint (string.string) violated – parent key not found ” error in Oracle database.

 

ORA-02291: integrity constraint (string.string) violated – parent key not found

 

Details of error are as follows.

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

Cause: A foreign key value has no matching primary key value.

Action: Delete the foreign key or add a matching primary key.





 

 

integrity constraint (string.string) violated – parent key not found

This ORA-02291 errors are related with the foreign key value has no matching primary key value.

To solve this error, you need to drop the foreign key or add a matching primary key.

Or firstly you need to insert the same value into the parent table, then you can insert the value into child table.

For example; I have 2 table which has relation between two table with EMPLOYEE_ID column as follows.

 

CREATE TABLE EMPLOYEE
( EMPLOYEE_ID numeric(10) not null,
NAME varchar2(50) not null,
LAST_NAME varchar2(50),
CONSTRAINT emp_pk PRIMARY KEY (EMPLOYEE_ID)
);

CREATE TABLE MANAGER
( ID numeric(10) not null,
EMPLOYEE_ID numeric(10) not null,
CONSTRAINT fk_EMPLOYEE
FOREIGN KEY (EMPLOYEE_ID)
REFERENCES EMPLOYEE (EMPLOYEE_ID)
);

 

I have inserted the following record.

INSERT INTO MANAGER (ID, EMPLOYEE_ID) VALUES (10, 63);

 

But I got this error, because 63 employee_id doesn’t exist in the employee table. So You need to insert this record to parent table, then you can insert the child table as follows.

 

INSERT INTO EMPLOYEE (EMPLOYEE_ID, NAME, LAST_NAME) VALUES (63, 'Mehmet ', 'Deveci ');

Then you can insert into the MANAGER table:

INSERT INTO MANAGER (ID, EMPLOYEE_ID) VALUES (10, 63);

 

Or you need to drop the emp_pk constraint.

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

Exit mobile version