gpt4 book ai didi

sql - 如何修复sql中的 "ORA-02270: no matching unique or primary key for this column-list "错误

转载 作者:行者123 更新时间:2023-12-04 23:46:24 24 4
gpt4 key购买 nike

问题发生在 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:此列列表没有匹配的唯一键或主键”。飞行表中正确引用了外键和主键,但我不明白为什么会出现此错误。

最佳答案

Route中的主键表是:

PRIMARY KEY(routeID, airportCode),

正确的外键引用需要按顺序引用两者。那将是:
FOREIGN KEY(routeID, airportCode) REFERENCES ROUTE(routeID, airportCode), 

然而, FLIGHT没有 airportCode ,所以这行不通。

我不确定你想朝哪个方向发展——删除 airportCode从主键或将其添加到 Flight table 。但这是你的问题。

关于sql - 如何修复sql中的 "ORA-02270: no matching unique or primary key for this column-list "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55869756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com