I am trying to get this SQL schema together for an Employee Database with four different tables (Employee information, Work information, company information, and manager information) and got the following error when attempting building the schema:
Schema Creation Failed: ORA-02291: integrity constraint (USER_4_07688.SYS_C00777054) violated - parent key not found
Here is my schema code:
create table Employee(
Lastname varchar(10),
FirstName varchar(10),
MidInitial char(1),
gender char(1),
street varchar(10),
city varchar(10),
primary key(Lastname, FirstName, MidInitial));
create table company(
company_name varchar(20),
city varchar(10),
primary key(company_name));
create table Works(
Lastname varchar(10),
FirstName varchar(10),
MidInitial char(1),
company_name varchar(20),
salary numeric(8,2),
primary key(Lastname, FirstName, MidInitial, company_name),
foreign key(Lastname, FirstName, MidInitial) references Employee,
foreign key(company_name) references company);
create table Manages(
Lastname varchar(10),
FirstName varchar(10),
MidInitial char(1),
ManagerLastname varchar(10),
MFirstName varchar(10),
MMidInitial char(1),
start_date date,
primary key(Lastname, FirstName, MidInitial, ManagerLastname, MFirstName, MMidInitial),
foreign key(Lastname, FirstName, MidInitial) references Employee);
I've been going over and over this but I can't seem to find where the integrity constraint error would be (I thought that all the foreign keys and whatnot lined up correctly)...
Could someone please let me know if they see any blatant errors in my code that could be causing this error?
Thanks so much!
---UPDATE---
I just tested out each foreign key with the rest of the schema individually and located the offending statement:
foreign key(company_name) references company);
The table this foreign key is referencing has already been created, so is there something else I'm missing? Thanks again!