database SQL 错误:ORA-02298:无法验证 (SYSTEM.AEROPUERTO_FK) - 未找到父键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4702310/
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
SQL Error: ORA-02298: cannot validate (SYSTEM.AEROPUERTO_FK) - parent keys not found
提问by andandandand
I'm getting the following error in on Oracle SQL Developer:
我在 Oracle SQL Developer 中收到以下错误:
Error starting at line 1 in command:
ALTER TABLE AEROPUERTO ADD CONSTRAINT AEROPUERTO_FK FOREIGN KEY (CODIGO_CIUDAD) REFERENCES CIUDAD(CODIGO)
Error report:
SQL Error: ORA-02298: cannot validate (SYSTEM.AEROPUERTO_FK) - parent keys not found
02298. 00000 - "cannot validate (%s.%s) - parent keys not found"
*Cause: an alter table validating constraint failed because the table has
child records.
*Action: Obvious
Why?
为什么?
回答by rsenna
There are records in AEROPUERTO
that point to records that do not exist in CIUDAD
.
有记录在AEROPUERTO
那个点到不存在的记录CIUDAD
。
To find out which records of AEROPUERTO
have that kind of issue:
要找出哪些记录AEROPUERTO
有这种问题:
select * from AEROPUERTO where CODIGO_CIUDAD not in (select CODIGO from CIUDAD)
If the result set is not empty, you dohave orphanaged records. You'll need to add the missing CIUDAD
records in order to create the AEROPUERTO_FK
foreign key, orupdate all the erroneous AEROPUERTO.CODIGO_CIUDAD
to null (if this is a nullable field, but you will lose the city information for those airport records).
如果结果集不为空,则您确实有孤立记录。您需要添加缺失的CIUDAD
记录以创建AEROPUERTO_FK
外键,或将所有错误更新AEROPUERTO.CODIGO_CIUDAD
为空(如果这是一个可为空的字段,但您将丢失这些机场记录的城市信息)。
回答by Amit Kumar
remove primary key constraint from the column in which you want to add the foreign key
从要添加外键的列中删除主键约束