Integrity constraint violation

Solved
Farhat1985 -  
Farhat1985 Posted messages 22 Status Membre -
Hello,

I have two tables to create in Oracle
department table:
CREATE TABLE dept(
DEPTNO NUMBER(2),
DNAME CHAR(20),
LOC CHAR(20),
constraint p1 primary key(deptno),
constraint c check( dname in ('ACCOUNTING','RESEARCH','SALLES','OPERATIONS')));

and an employee table:
create table emp (
empno number (5),
ename varchar (40),
job varchar(40),
mgr number(5),
hiredate date,
sal number(6),
comm number(6),
deptno number(2),
CONSTRAINT E_CLEP PRIMARY KEY(EMPNO),
CONSTRAINT E_CLET1 FOREIGN KEY(DEPTNO) REFERENCES
DEPT(DEPTNO),
CONSTRAINT E_CLET2 FOREIGN KEY(MGR) REFERENCES EMP(EMPNO));

and the following data for the dept table:
insert into dept values (10,'ACCOUNTING','NEW-YORK');
insert into dept values (20,'RESEARCH','Dallas');
insert into dept values (30,'SALLES','Chicago');
insert into dept values (40,'OPERATIONS','Boston');
insert into dept values (50,'SALLES','Tunis');

so far so good

but the problem arises when I try to insert data into the emp table:
insert into emp values(7499,'ALLEN','SALESMAN',7698,'20/02/81',160000,30000,30);

when I execute on sql+ this error message is displayed on the terminal:
ORA:02291 : integrity constraint violation <base.E_CLET2> parent key not found.

Thank you in advance for your help.

1 réponse

jee pee Posted messages 31932 Registration date   Status Modérateur Last intervention   9 957
 
Hi,

You need to enter users in hierarchical order.

To create an employee, you must first create their manager in the database (E_CLET2 FOREIGN KEY(MGR) REFERENCES EMP(EMPNO).

The 7698 must exist to create the 7499.

Regards,

A foreigner is a friend we haven't met yet.
4
Farhat1985 Posted messages 22 Status Membre
 
You're welcome :)
0