ORA-02291 indicates the database couldn't find a matching parent key value
CREATE TABLE departments
(department_id number(10) not null,
department_name varchar2(50) not null,
CONSTRAINT departments_pk PRIMARY KEY (department_id)
);
insert into departments ( department_id, department_name )values(1,'Data Group' );
insert into departments ( department_id, department_name )values(2,'Purchasing' );
insert into departments ( department_id, department_name )values(3,'Call Center' );
insert into departments ( department_id, department_name )values(4,'Communication' );
CREATE TABLE employees
( employee_id number(10) not null,
last_name varchar2(50) not null,
job_id varchar2(30),
department_id number(10),
salary number(6),
manager_id number(6),
CONSTRAINT employees_pk PRIMARY KEY (employee_id),
CONSTRAINT fk_departments FOREIGN KEY (department_id)
REFERENCES departments(department_id)
);
SQL> insert into employees( employee_id, last_name, job_id, salary,department_id ,manager_id)
2 values( 1001, 'Lawson', 'MGR', 30000, 6, 1004);
insert into employees( employee_id, last_name, job_id, salary,department_id ,manager_id)
*
ERROR at line 1:
ORA-02291: integrity constraint (SYS.FK_DEPARTMENTS) violated - parent key not
found
SQL>
Home »
Oracle »
Table »
Oracle »
Table »
Foreign Key:
- Foreign Key
- ORA-02291 indicates the database couldn't find a matching parent key value
- ORA-02292: attempt to delete a row in the parent table that has dependent child rows
Related: