SQL 未找到 Oracle 父密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9773631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle parents key not found
提问by David Garcia
Im trying to add a constraint to a reservation table, the reservation can either be for a flight or accommodation or both.
我试图向预订表添加约束,预订可以是航班或住宿,也可以是两者。
- First 4 records booked inward flight, outward flight and accommodation
- Next 4 records booked a flight only and have
acc_id
set toNULL
- Following 2 records booked only accommodation, hence in flight, out flight and seats are set to null.
- 前 4 条记录预订了进港、出港和住宿
- 接下来的 4 条记录仅预订了航班并且已
acc_id
设置为NULL
- 以下 2 条记录仅预订了住宿,因此在飞行中,出境和座位设置为空。
Here are my constraints for this table
这是我对此表的限制
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT HOLIDAY_PK PRIMARY KEY (RESV_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT CUSTOMER_FK FOREIGN KEY (BOOKING_CUS_ID) REFERENCES CUSTOMER (CUS_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT STAFF_FK3 FOREIGN KEY (EMP_ID) REFERENCES STAFF (EMP_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK FOREIGN KEY (IN_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK1 FOREIGN KEY (OUT_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT ACC_FK FOREIGN KEY (ACC_ID) REFERENCES ACCOMMODATION (ACC_ID);
and the only constraint that is yielding an error is;
产生错误的唯一约束是;
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK1 FOREIGN KEY (OUT_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);
I get
我得到
ERROR at line 1:
ORA-02298: cannot validate (U1146815.FLIGHT_FK1) - parent keys not found
What seems to be the problem? i understand that it has to do with orphan childs, but i am setting nulls so i dont understand, please advise
似乎是什么问题?我知道这与孤儿有关,但我正在设置空值,所以我不明白,请指教
回答by Justin Cave
The error indicates that the FLIGHT
table does not have an entry for at least one of the FLI_ID
values between 11 and 18. You'd need to insert a row in the FLIGHT
table for whatever flights are missing or update your table to have a different OUT_FLIGHT_ID
.
该错误表明该FLIGHT
表中至少没有FLI_ID
11 到 18 之间的值之一的条目。您需要在FLIGHT
表中插入一行以查找缺少的任何航班或更新您的表以使用不同的OUT_FLIGHT_ID
.
回答by Mohammad Shahnawaz
Delete all the rows from the child table which is being used to alter the column for having the references.
从子表中删除所有行,该行用于更改具有引用的列。
ALTER TABLE sales ADD CONSTRAINT sales_time_fk
FOREIGN KEY (time_id) REFERENCES times (time_id)
RELY DISABLE NOVALIDATE;