违反-未找到父键02291.00000-“完整性约束" [英] Violated - parent key not found 02291. 00000 - "integrity constraint

查看:102
本文介绍了违反-未找到父键02291.00000-“完整性约束"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Oracle SQL开发人员中开发数据库,​​试图从另一个表访问foriegn键.我目前正在使用以下CREATE语句

Hi I am developing a database in Oracle SQL dev, that is trying to access foriegn keys from another table. I am currently working on the ItemOrdered table which I've created with the following CREATE statement

CREATE TABLE ItemOrdered(OrderID varchar2(9) REFERENCES Ords(OrderID),
BeltID varchar2(9) REFERENCES BeltID(BeltID), 
Quantity varchar(4) NOT NULL,
PRIMARY KEY(OrderID, BeltID))

您可以看到,我具有以下前键Ords和BeltID.

As you can See I have the following foriegn keys Ords and BeltID.

现在,当我尝试运行以下语句

Now when I try to run the following statement

INSERT INTO ItemOrdered VALUES(401565981,234489212,'2')

它给我以下错误

已违反-未找到父密钥 02291. 00000-违反完整性约束(%s.%s)-找不到父键"

violated - parent key not found 02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"

如果需要,我已经提供了Ords CREATE语句

I have provided my Ords CREATE statement if its needed

  CREATE TABLE Ords(OrderID varchar2(9) PRIMARY KEY, 
CustomerID varchar(9) REFERENCES Customers(CustomerID), 
    Expected_Delivery_Date date DEFAULT sysdate NOT NULL, 
Actual_Delivery_Date date DEFAULT sysdate NOT NULL, 
    Payment_Due_Date date DEFAULT sysdate NOT NULL, 
Order_Date date DEFAULT sysdate NOT NULL, Price Varchar(10), 
    Order_Placed varchar2(1) CONSTRAINT OrderPlaced 
CHECK(Order_Placed IN('Y','N')) NOT NULL, 
Order_Confirmed varchar2(1)
    CONSTRAINT Order_Confirmed CHECK(Order_Confirmed IN('Y','N')) NOT NULL, 
Order_Completed varchar2(1) CONSTRAINT Order_Completed
    CHECK(Order_Completed IN('Y','N')) NOT NULL)

我还提供了BeltID CREATE语句

And I have also provided my BeltID CREATE statement

    CREATE TABLE BeltID(BeltID varchar2(9) PRIMARY KEY, 
BeltLengthID varchar2(9) REFERENCES BeltLength(BeltLengthID), 
    ColourID varchar2(9) REFERENCES Colour(ColourID), 
DesignID varchar2(9) REFERENCES Design(DesignID),ComponentID varchar2(9) REFERENCES Component(ComponentID))

我似乎不太明白为什么会出现此错误.为什么有明确的解释?

I don't seem to quite understand why I am getting this error. Is there an clear explanation why?

这是我要执行的操作的http链接. 链接文本

Here is the http link of what I am trying to do. link text

推荐答案

由于创建表ItemOrdered时指定的外键约束以及执行此插入操作的时间,

Due to the foreign key constraints you specified when you created table ItemOrdered, when you perform this insert:

INSERT INTO ItemOrdered VALUES(401565981,234489212,'2')

...值401565981和234489212必须分别对应于Ords和BelitId表中的键值-即,这两个查询应返回行:

... the values 401565981 and 234489212 must correspond to key values in the Ords and BelitId tables respectively - i.e. these 2 queries should return rows:

select *
from Ords
where OrderId = 401565981;

select *
from BeltId
where BeltId = 234489212;

错误消息表明情况并非如此.

The error message suggests this is not the case.

这篇关于违反-未找到父键02291.00000-“完整性约束"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆