0

我正在尝试为具有四个不同表(员工信息、工作信息、公司信息和经理信息)的员工数据库获取此 SQL 架构,并在尝试构建架构时出现以下错误:

Schema Creation Failed: ORA-02291: integrity constraint (USER_4_07688.SYS_C00777054) violated - parent key not found

这是我的架构代码:

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);

我一直在重复这个,但我似乎无法找到完整性约束错误的位置(我认为所有的外键和诸如此类的东西都没有正确排列)......

如果有人在我的代码中看到任何可能导致此错误的明显错误,请告诉我?

非常感谢!

- -更新 - -

我刚刚用其余的模式分别测试了每个外键并找到了有问题的语句:

foreign key(company_name) references company);

该外键引用的表已经创建,所以我还缺少其他东西吗?再次感谢!

4

0 回答 0