此问题发生在FLIGHT表上,
create table LOCATION (
airportCode VARCHAR2(10) not null,
country VARCHAR2(15) not null,
address VARCHAR2(50) not null,
PRIMARY KEY(airportCode));
create table ROUTE (
routeID VARCHAR2(10) not null,
airportCode VARCHAR2(10) not null,
description VARCHAR2(100) not null,
PRIMARY KEY(routeID, airportCode),
FOREIGN KEY(airportCode) REFERENCES LOCATION(airportCode));
create table NEACC (
memberID VARCHAR2(20),
flightGoldpoints NUMBER,
PRIMARY KEY(memberID));
create table STAFF (
staffID VARCHAR2(20) not null,
memberID VARCHAR2(20) not null,
name VARCHAR2(20) not null,
address VARCHAR2(50) not null,
email VARCHAR2(30) not null,
phone NUMBER not null,
passportNum NUMBER not null,
PRIMARY KEY(staffID),
FOREIGN KEY(memberID) REFERENCES NEACC(memberID));
create table FLIGHT (
flightID VARCHAR2(20) not null,
routeID VARCHAR2(20) not null,
staffID VARCHAR2(20) not null,
captainOrFirstOfficer VARCHAR2(15) CHECK (captainOrFirstOfficer IN ('captain', 'first officer')) not null,
estDepartDateTime VARCHAR2(20) not null,
actDepartDateTime VARCHAR2(20) not null,
actArriveDateTime VARCHAR2(20) not null,
avgSpeed NUMBER not null,
avgHeight NUMBER not null,
estDuration NUMBER not null,
estFuel NUMBER not null,
PRIMARY KEY(flightID, routeID),
FOREIGN KEY(routeID) REFERENCES ROUTE(routeID),
FOREIGN KEY(staffID) REFERENCES STAFF(staffID));
我得到的错误是“ ORA-02270:此列列表没有匹配的唯一键或主键”。飞行表中正确引用了外键和主键,但我不明白为什么会出现此错误。
答案 0 :(得分:2)
Route
表中的主键是:
PRIMARY KEY(routeID, airportCode),
正确的外键引用需要依次引用两者。那应该是:
FOREIGN KEY(routeID, airportCode) REFERENCES ROUTE(routeID, airportCode),
但是,FLIGHT
没有airportCode
,因此无法正常工作。
我不确定您要朝哪个方向走-从主键中删除airportCode
或将其添加到Flight
表中。但这是你的问题。