ORA-02291: integrity constraint: parent key not found
来源:互联网 发布:js div显示 编辑:程序博客网 时间:2024/05/28 05:17
hibernate operation: Could not execute JDBC batch update; SQL [insert into
dchnpricecarchancesource (inpricecard_id, pricecard_id, count, sumcount, source_code, reason_code,
ingroup_id, op_login, op_groupid, op_time, change_source, memo1, memo2, change_id) values (?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; ORA-02291: integrity constraint
(DBCHNADM.FK_DCHNPRIC_REFERENCE_DCHNPRIC) violated - parent key not found ; nested exception is
Java.sql.BatchUpdateException: ORA-02291: integrity constraint
(DBCHNADM.FK_DCHNPRIC_REFERENCE_DCHNPRIC) violated - parent key not found
---------------------------------------------------------------------------------------------------------------------------
参看了这本书第八章:
《Oracle Database 11g SQL开发指南》<oracle database 11g SQL Master SQL and PL/SQL in the Oracle Database>
8.5.2 外键约束
所谓外键关系就是一个表中的列引用了其他表中的列。例如,products表中的product_type_id列引用了
product_types表中的product_type_id列。product_types表称为父表(parent table),而products表则称为子
表(child table),这是因为products表中的product_type_id列依赖于product_types表中的product_type_id
列。
如果试图向products表中插入一行,但此行的product_type_id不存在,数据库就会返回ORA-02291错误。这个错
误说明数据库无法找到一个匹配的父键值(此处父键就是product_types表中的product_type_id列)。在下面这个
例子中,就返回这样一个错误,因为product_types表中不存在product_type_id为6的行:
SQL> INSERT INTO products (
2 product_id, product_type_id, name, description, price
3 ) VALUES (
4 13, 6, 'Test', 'Test', NULL
5 );
INSERT INTO products (
*
ERROR at line 1:
ORA-02291: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - parent key not found
同理,如果试图将products表中一行的product_type_id列设置为一个不存在的父键值,数据库也会返回相同的
错误。例如:
SQL> UPDATE products
2 SET product_type_id = 6
3 WHERE product_id = 1;
UPDATE products
*
ERROR at line 1:
ORA-02291: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - parent key not found
如果试图从父表中删除已经有依赖子行的一行,数据库就会返回ORA-02292错误。例如,如果试图删除
product_types表中 product_type_id列为1的行,数据库就会返回ORA-02292错误,因为products表中包含了
product_type_id列等于1的行:
SQL> DELETE FROM product_types
2 WHERE product_type_id = 1;
DELETE FROM product_types
*
ERROR at line 1:
ORA-02292: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - child record found
如果数据库允许执行这个删除操作,那么子行就无效了,因为它们不能指向父表中的有效值了。
---------------------------------------------------------------------------------------------------------------------
dchnpricecarchancesource (inpricecard_id, pricecard_id, count, sumcount, source_code, reason_code,
ingroup_id, op_login, op_groupid, op_time, change_source, memo1, memo2, change_id) values (?, ?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; ORA-02291: integrity constraint
(DBCHNADM.FK_DCHNPRIC_REFERENCE_DCHNPRIC) violated - parent key not found ; nested exception is
Java.sql.BatchUpdateException: ORA-02291: integrity constraint
(DBCHNADM.FK_DCHNPRIC_REFERENCE_DCHNPRIC) violated - parent key not found
---------------------------------------------------------------------------------------------------------------------------
参看了这本书第八章:
《Oracle Database 11g SQL开发指南》<oracle database 11g SQL Master SQL and PL/SQL in the Oracle Database>
8.5.2 外键约束
所谓外键关系就是一个表中的列引用了其他表中的列。例如,products表中的product_type_id列引用了
product_types表中的product_type_id列。product_types表称为父表(parent table),而products表则称为子
表(child table),这是因为products表中的product_type_id列依赖于product_types表中的product_type_id
列。
如果试图向products表中插入一行,但此行的product_type_id不存在,数据库就会返回ORA-02291错误。这个错
误说明数据库无法找到一个匹配的父键值(此处父键就是product_types表中的product_type_id列)。在下面这个
例子中,就返回这样一个错误,因为product_types表中不存在product_type_id为6的行:
SQL> INSERT INTO products (
2 product_id, product_type_id, name, description, price
3 ) VALUES (
4 13, 6, 'Test', 'Test', NULL
5 );
INSERT INTO products (
*
ERROR at line 1:
ORA-02291: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - parent key not found
同理,如果试图将products表中一行的product_type_id列设置为一个不存在的父键值,数据库也会返回相同的
错误。例如:
SQL> UPDATE products
2 SET product_type_id = 6
3 WHERE product_id = 1;
UPDATE products
*
ERROR at line 1:
ORA-02291: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - parent key not found
如果试图从父表中删除已经有依赖子行的一行,数据库就会返回ORA-02292错误。例如,如果试图删除
product_types表中 product_type_id列为1的行,数据库就会返回ORA-02292错误,因为products表中包含了
product_type_id列等于1的行:
SQL> DELETE FROM product_types
2 WHERE product_type_id = 1;
DELETE FROM product_types
*
ERROR at line 1:
ORA-02292: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - child record found
如果数据库允许执行这个删除操作,那么子行就无效了,因为它们不能指向父表中的有效值了。
---------------------------------------------------------------------------------------------------------------------
后来发现是在表中外键设置错误造成的,引以为戒:
转自:http://hi.baidu.com/skyforum/blog/item/37611a2e25a8205a4ec2262f.html
0 0
- ORA-02291: integrity constraint: parent key not found
- ORA-02291: integrity constraint (INFORES_GZ_PJ2.FK_TC_DEV_PROPERTY_GRP_PROID) violated - parent key
- ORA-02291:parent key not found
- java.sql.BatchUpdateException: ORA-02291: integrity constraint
- ORA-02292: integrity constraint (BLDBANK.F_YXDH) violated - child record found
- java.sql.SQLException: ORA-02291: integrity constraint violated - par
- ORA-02291: integrity constraint (SYSTEM.FK1170E5C5328E4352) violated 解决办法
- ORA-02298 Parent Keys Not Found?解决办法
- ORA-02292:integrity constraint(xx) violated - child record found 外键关联,无法删除记录
- ORA-02292:integrity constraint(xx) violated
- 解决ORA-08102: index key not found
- ORA-08102: index key not found
- Unable to create unique key constraint (ID) on table XXX: ID not found
- 报错:Duplicate key or integrity constraint violation message from server
- 操作MySQL报出: Duplicate key or integrity constraint violation message from server 问题解决
- SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '5-47' for key 'PRIMARY'
- ora-08102:index key not found,obj#57848,file 6, block 6324(2)
- ORA-08102:index key not found, obj# 52485, file 19,block 399461 (2)
- leetcode:clone graph
- gradle 打包APK
- Android Studio 常用快捷方法(持续更新)
- SpringMVC中的ContentNegotiatingViewResolver配置
- 《C专家编程》:函数如何返回一个数组(九)
- ORA-02291: integrity constraint: parent key not found
- halcon -1
- 设计基于HTML5的APP登录功能及安全调用接口的方式(原理篇)
- oracle分区表备份恢复
- [leetcode]111.Minimum Depth of Binary Tree
- Middle-题目52:78. Subsets
- state
- halcon-2
- 大容量数据从SQLSever表中导出到本地(bcp工具的使用)