我正在创建一个试图从外键访问值的数据库.我创建了两个下表
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')
这是两个表. Component和TypeComponent. Component是TypeComponent的父实体,我试图运行以下INSERT语句:
INSERT INTO Component VALUES(192359823,785404309)
但它给了我错误
这是我在Oracle sql dev中到目前为止的会话
解决方法
首先尝试在TypeComponent表中插入,然后插入到Component表中.
根据错误:
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.
这意味着您引用的表中没有匹配的键.
编辑#1
有关您的信息,请访问以下网站,您可以从中获得有关所有Oracle错误代码的帮助.
HTTP:// [ORA-02291] .ORA-code.com /
这是该网站的主页:http://www.ora-code.com/