ORA-02292: integrity constraint (xxxx) violated - child record found
在更新表的主键字段或DELETE数据时,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 这个是因为主外键关系,下面借助一个小列子来描述一下这个错误:
SQL> create table student
2 (
3 id number,
4 name nvarchar2(12),
5 constraint pk_student primary key(id)
6 );
Table created.
QL> create table grades
2 ( id number ,
3 subject nvarchar2(12),
4 scores number,
5 constraint pk_grades primary key(id ,subject),
6 constraint fk_student_id foreign key(id) references student(id)
7 );
Table created.
SQL> insert into student
2 values(1001,'kerry');
1 row created.
SQL> insert into student
2 values(1002,'jimmy');
1 row created.
SQL> commit;
Commit complete.
SQL> insert into grades
2 values(1001, 'math', 120);
1 row created.
SQL> insert into grades
2 values(1001, 'english', 106);
1 row created.
SQL> commit;
Commit complete.
SQL> update student set id=1004 where name='kerry';
update student set id=1004 where name='kerry'
*
ERROR at line 1:
ORA-02292: integrity constraint (TEST.FK_STUDENT_ID) violated - child record
found
SQL>
遇到这种情况,首先找到外键约束和相关表,禁用外键约束,处理数据,然后启用外键约束。
SELECT OWNER, CONSTRAINT_NAME, TABLE_NAME
FROM DBA_CONSTRAINTS
WHERE CONSTRAINT_NAME=&CONSTRAINT_NAME;
SELECT OWNER, CONSTRAINT_NAME, TABLE_NAME
FROM USER_CONSTRAINTS
WHERE CONSTRAINT_NAME=&CONSTRAINT_NAME;
SQL> ALTER TABLE TEST.GRADES DISABLE CONSTRAINT FK_STUDENT_ID;
Table altered.
SQL> update student set id=1004 where name='kerry';
1 row updated.
SQL> update grades set id=1004 where id =1001;
2 rows updated.
SQL> commit;
Commit complete.
SQL> ALTER TABLE TEST.GRADES ENABLE CONSTRAINT FK_STUDENT_ID;
Table altered.
SQL>
如果是删除数据遇到这种情况,可以先删除子表数据,然后删除父表数据。
SQL> delete from student where id=1004;
delete from student where id=1004
*
ERROR at line 1:
ORA-02292: integrity constraint (TEST.FK_STUDENT_ID) violated - child record
found
SQL> delete from grades
2 where id in
3 ( select id from student
4 where id=1004);
2 rows deleted.
SQL> delete from student where id=1004;
1 row deleted.
SQL> commit;
Commit complete.
SQL>
ORA-02292: integrity constraint (xxxx) violated - child record found的更多相关文章
- 修复Magento SQLSTATE[23000]: Integrity constraint
magneto在意外情况下报错Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry,出现这个问题最 ...
- 报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'
在提交注册信息的时候报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key ' ...
- 关于 Oracle DB CONSTRAINT约束的一些SQL ORA-02292: integrity constraint violated
ALTER TABLE table_name DISABLE CONSTRAINT constraint_name; select * from all_constraints where owner ...
- Oracle数据库出现[23000][2291] ORA-02291: integrity constraint (SIMTH.SYS_C005306) violated异常
参考链接 这个异常发生在往中间表中插入数据时,这时出现异常是因为关联的某个表没有插入数据,所以给没有插入数据的关联表插入数据,再给中间表插入数据此时异常就会解决.
- laravel报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' (SQL: insert into `cart` (`uid`, `gid`, `gname`, `price`) values (3, 21, 夏季日系复古工装短袖衬衫男士印花潮流宽松五分
原因:要操作的数据表id没有设置自增,导致出现id为0的情况 解决方法:给该数据表的id字段设置自增
- SQL基础--> 约束(CONSTRAINT)
--============================= --SQL基础--> 约束(CONSTRAINT) --============================= 一.几类数据完 ...
- SQL Server - 约束 CONSTRAINT
总结 约束放置在表中,以下五种约束: NOT NULL 非空约束C 指定的列不允许为空值 UNIQUE 唯一约束U 指定的列中没有重复值,或该表中每一个值或者每一组值都将是唯一的 PRIMARY KE ...
- constraint、index、view(day04)
回顾: 1.sql99中的表连接 select 字段列表 from 左表 {[inner]|{left|right|full} [outer]} join 右表 on 关联条件; 集合操作 union ...
- ocp 1Z0-042 1-60题解析
1. Because of a power outage,instance failure has occurred. From what point in the redo log does rec ...
随机推荐
- Windows Server 2008 下解析二级域名的方法
昨天去了客户那里部署网站,用的是客户那边的windows server 2008. 本文主要以总结问题点的形式来说. 问题1:本机的数据库是SQL SERVER 2008R2,客户那边的数据库是SQL ...
- 将Resource中的图片资源动态绑定到PictureBox中:
//CurrentCommunication为解决方案的名字,dynamic为图片的名字 pictureBox1.Image = CurrentCommunication.Properties.Res ...
- 【LeetCode】Verify Preorder Serialization of a Binary Tree(331)
1. Description One way to serialize a binary tree is to use pre-order traversal. When we encounter a ...
- ECMAScript 5中属性的特性值
这是<JavaScript高级程序设计(第三版)>第六章相关内容的总结. ECMAScript中有两种属性:数据属性和访问器属性.每种属性都有四个特性值. 数据属性的四个特性值: [[Co ...
- 开始编写CSS
本文由大漠根据Krasimir Tsonev的<Starting to Write CSS>所译,整个译文带有我们自己的理解与思想,如果译得不好或不对之处还请同行朋友指点.如需转载此译文, ...
- .net登录的一般模式
思路: 1.检查登录: private string CheckLogin(HttpContext context) { Model.TUser model = (Model.TUser)contex ...
- 图解SQL的Join(转)
对于SQL的Join,在学习起来可能是比较乱的.我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚.Codin ...
- Spring MVC 处理静态资源文件
摘要: 三个方案: 1.方案一:激活Tomcat的defaultServlet来处理静态文件 2.方案二: 在spring3.0.4以后版本提供了mvc:resources (需要配置annotati ...
- div的显示和隐藏以及点击图标的更改
- java 字符串操作和日期操作
一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...
