ORA-02291:parent key not found
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
如果数据库允许执行这个删除操作,那么子行就无效了,因为它们不能指向父表中的有效值了。
---------------------------------------------------------------------------------------------------------------------
后来发现是在表中外键设置错误造成的,引以为戒:
转自:http://hi.baidu.com/skyforum/blog/item/37611a2e25a8205a4ec2262f.html
ORA-02291:parent key not found的更多相关文章
- Foreign key (referential) constraints on DB2 LUW v105
oreign key constraints (also known as referential constraints or referential integrity constraints) ...
- Oracle Database 11g express edition
commands : show sys connect sys as sysdba or connect system as sysdba logout or disc clear screen or ...
- ocp 1Z0-047 61-130题解析
61. Evaluate the following SQL statements that are issued in the given order:CREATE TABLE emp(emp_no ...
- Oracle Lock(Enqueues)
转载:http://www.cnblogs.com/Richardzhu/articles/2796540.html 数据库是一个多用户使用的共享资源.当多个用户并发地存取数据时,在数据库中就会产生多 ...
- jQuery-template.js学习
花了点时间,看了下jQuery-template.js,不多废话,先上结构 jQuery.each({..},function(){}) jQuery.fn.extend({..}) jQuery.e ...
- CSS3与页面布局学习总结(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
- 【移动前端开发实践】从无到有(统计、请求、MVC、模块化)H5开发须知
前言 不知不觉来百度已有半年之久,这半年是996的半年,是孤军奋战的半年,是跌跌撞撞的半年,一个字:真的是累死人啦! 我所进入的团队相当于公司内部创业团队,人员基本全部是新招的,最初开发时连数据库都没 ...
- Oracle事务
Oracle事务的ACID特性 原子性Atomicity:事务中的所有动作要么都发生,要么都不发生. 一致性Consistency:事务将数据库从一种状态转变为下一种一致状态. 隔离性Isolatio ...
- CSS3与页面布局学习笔记(七)——前端预处理技术(Less、Sass、CoffeeScript、TypeScript)
CSS不像其它高级语言一样支持算术运算.变量.流程控制与面向对象特性,所以CSS样式较多时会引起一些问题,如修改复杂,冗余,某些别的语言很简单的功能实现不了等.而javascript则是一种半面向对象 ...
随机推荐
- Pandas速查手册中文版(转)
关键缩写和包导入 在这个速查手册中,我们使用如下缩写: df:任意的Pandas DataFrame对象 同时我们需要做如下的引入: import pandas as pd 导入数据 pd.read_ ...
- Android基础------Intent组件
1.什么是intent 同Activity一样,也是Android应用组件在Android中承担着一种指令输出的作用Intent负责对应用中一次操作的动作及动作相关的数据进行描述.Android则根据 ...
- 将下载到本地的JAR包手动添加到Maven仓库(转)
常用Maven仓库网址:http://mvnrepository.com/http://search.maven.org/http://repository.sonatype.org/content/ ...
- 【bzoj1202】[HNOI2005]狡猾的商人 带权并查集
题目描述 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 Ai大于0时表 ...
- wsgiref 源码解析
Web Server Gateway Interface(wsgi),即Web服务器网关接口,是Web服务器软件和用Python编写的Web应用程序之间的标准接口. 想了解更多关于WSGI请前往: h ...
- [牛客Wannafly挑战赛27D]绿魔法师
description newcoder 给你一个空的可重集合\(S\). \(n\)次操作,每次操作给出\(x\),\(k\),\(p\),执行以下操作: \(opt\ 1\):在S中加入x. \( ...
- BZOJ4259:残缺的字符串——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4259 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度 ...
- BZOJ2823 [AHOI2012]信号塔 【最小圆覆盖】
题目链接 BZOJ2823 题解 最小圆覆盖模板 都懒得再写一次 #include<iostream> #include<cstdio> #include<cmath&g ...
- HDOJ(HDU).1016 Prime Ring Problem (DFS)
HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...
- Communications link failure
针对数据库Communications link failure的错误,可以理解为有两种策略解决: 策略1(推荐): 数据池配置 <property name="minEvic ...