--Create Flight schedule table
CREATE TABLE FlightSchedule
(RouteID VarChar(6),
FlightDate DATE NOT NULL,
PlaneSerial VarChar(10) NOT NULL,
CONSTRAINT FlightIDDATEPK PRIMARY KEY(RouteID, FlightDate),
CONSTRAINT FlightNoFK FOREIGN KEY(RouteID)
REFERENCES ROUTE(RouteID),
CONSTRAINT PlaneSerialFK FOREIGN KEY(PlaneSerial)
REFERENCES AIRPLANE(PlaneSerial));
--Create Crew table
CREATE TABLE Crew
(EmpID NUMBER(5) NOT NULL,
RouteID Varchar(6) NOT NULL,
FlightDate DATE NOT NULL,
CONSTRAINT EMPIDPK PRIMARY KEY(EmpID, RouteID, FlightDate),
CONSTRAINT EMPIDFK FOREIGN KEY(EmpID)
REFERENCES EMPLOYEE(EmpID),
CONSTRAINT RouteIDFK FOREIGN KEY(RouteID)
REFERENCES ROUTE(RouteID),
CONSTRAINT DATEFK FOREIGN KEY(FlightDate)
REFERENCES FlightSchedule(FlightDate));
我正在尝试创建2个表,但收到以下错误。已经设置了主键但不知道出了什么问题。
Error at Command Line : 26 Column : 28
Error report -
SQL Error: ORA-02270: no matching unique or primary key for this column-list
02270. 00000 - "no matching unique or primary key for this column-list"
*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement
gives a column-list for which there is no matching unique or primary
key constraint in the referenced table.
*Action: Find the correct column names using the ALL_CONS_COLUMNS
catalog view
答案 0 :(得分:0)
外键需要引用父表主键的所有列(或者您引用的唯一约束的所有列)。如果FlightSchedule
的主键为RouteID, FlightDate
,则引用Crew
的{{1}}的外键需要使用主键的两列
FlightSchedule
当然,您需要确保所有外键都引用父表中的完整键。您尚未发布您引用的其他表的定义,因此我不知道您的外键是否存在相同的问题。