SQL错误:ORA-02291:完整性约束 [英] SQL Error: ORA-02291: integrity constraint

查看:575
本文介绍了SQL错误:ORA-02291:完整性约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个试图从外键访问值的数据库.我创建了以下两个表

I am creating a database that is trying to access values from a foreign key. I have created two following tables

CREATE TABLE Component(
    ComponentID varchar2(9) PRIMARY KEY
    , TypeID varchar2(9) REFERENCES TypeComponent(TypeComponentID)
)

INSERT INTO Component VALUES(192359823,785404309)
INSERT INTO Component VALUES(192359347,785404574)
INSERT INTO Component VALUES(192359467,785404769)
INSERT INTO Component VALUES(192359845,785404867)
INSERT INTO Component VALUES(192359303,785404201)
INSERT INTO Component VALUES(192359942,785404675)


CREATE TABLE TypeComponent (
    TypeComponentID varchar2(9) PRIMARY KEY
    , Type_Description varchar2(30) CONSTRAINT Type_Description 
        CHECK(Type_Description IN('Strap', 'Buckle', 'Stud')) NOT NULL
)

INSERT INTO TypeComponent VALUES(785404309, 'Strap')
INSERT INTO TypeComponent VALUES(785404574, 'Stud')
INSERT INTO TypeComponent VALUES(785404769, 'Buckle')
INSERT INTO TypeComponent VALUES(785404867, 'Strap')
INSERT INTO TypeComponent VALUES(785404201, 'Buckle')
INSERT INTO TypeComponent VALUES(785404675, 'Stud')

这是两个表. ComponentTypeComponent. ComponentTypeComponent的父实体,我正在尝试运行以下INSERT语句:

These are the two tables. Component and TypeComponent. Component is the parent entity to TypeComponent, and I am trying to run the following INSERT statement:

INSERT INTO Component VALUES(192359823,785404309)

但是它给了我错误

这是我到目前为止在Oracle SQL开发人员中进行的会话

This is the session that I have so far in Oracle SQL dev

推荐答案

尝试先在TypeComponent表中插入,然后再插入Component表.

Try inserting in your TypeComponent table first, then insert into your Component table.

根据错误:

ORA-02291:   完整性约束(string.string)被违反-未找到父键
原因::外键值没有匹配的主键值.
操作:           "删除外键或添加匹配的主键.

ORA-02291:    integrity constraint (string.string) violated - parent key not found
Cause:            A foreign key value has no matching primary key value.
Action:            Delete the foreign key or add a matching primary key.

这意味着您引用的表中没有匹配的键.

This means that there is no matching key in your referenced table.

编辑#1

有关种类的信息,请访问以下站点,以获取有关所有Oracle错误代码的帮助.

For your kind information, here is a site where you can get help with all of the Oracle error codes.

http://[ora-02291].ora-code.com/

这是此网站的主页: http://www.ora-code.com/

Here's the homepage for this site: http://www.ora-code.com/

您可以在该位置替换URL中的错误代码以适合您得到的错误代码,然后您将访问该错误的页面.

Where you may replace the error code in the URL to suit the error code you're getting, and you'll access to the page for this error.

这篇关于SQL错误:ORA-02291:完整性约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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