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 ...
随机推荐
- 使用openfiler设置SMB/CIFS共享总是不通过的一例与解决办法
最近使用openfiler进行空闲存储的集中化管理与多主机节点共享,等设置到了SMB/CIFS的时候总是通过不了,前提需要开启的LDAP内建在openfiler也都开启并设置好了,但就是无法通过&qu ...
- C++指针和动态内存分配
指针和动态内存分配 数组与指针 数组 数组名是一个指针常量. 数组名传递数据时,传递的是地址. 数组作为函数参数时不指定第一维大小. 对象数组 A a[2] = {A(1,2)}; 执行时先调用有参数 ...
- 主机巡检脚本:OSWatcher.sh
主机巡检脚本:OSWatcher.sh 2016-09-26更新,目前该脚本只支持Linux操作系统,后续有需求可以继续完善. 注意: 经测试,普通用户执行脚本可以顺利执行前9项检查: 第10项,普通 ...
- git开发流程、常用命令及工具、TortoiseGit使用及常见问题
根据我最近使用git的一些经历,git是基于分支的版本控制工具,分支有远程分支和本地分支. 一.开发流程 - 从远程服务器的master,clone一份项目文件到本地,然后本地master的基础上br ...
- Generator库co4.6使用及源码分析
原文链接 http://www.cnblogs.com/ytu2010dt/p/6043947.html co4.x已经抛弃了原来thunk转而结合promise实现. 一:promise proms ...
- Sql Server函数全解(三)数据类型转换函数和文本图像函数
一:数据类型转换函数 在同时处理不同数据类型的值时,SQL Server一般会自动进行隐士类型转换.对于数据类型相近的值是有效的,比如int和float,但是对于其它数据类型,例如整型和字符类型,隐士 ...
- 重启SQL Server——总是好事?
在实际工作中,我经常看到——有时人们定期重启SQL Server!我们都希望接受,SQL Server的定期重启并不真的是一个好主意.但在今天的文章里,我想进一步讨论下,当你定期重启你的SQL Ser ...
- JS的解析与执行过程
JS的解析与执行过程 全局中的解析和执行过程 预处理:创建一个词法环境(LexicalEnvironment,在后面简写为LE),扫描JS中的用声明的方式声明的函数,用var定义的变量并将它们加到预处 ...
- 用jquery实现抽奖小程序
用jquery实现抽奖小程序 这些日子,到处都可以看到关于微信小程序的新闻或报到,在博客园中写关于微信小程序的也不少.但是今天我要说的不是微信小程序,而是用简单的jquery写的一个好玩的抽奖小程序. ...
- 7.5 数据注解特性--MaxLength&&MinLength
MaxLength attribute can be applied to a string or array type property of a domain class. EF Code Fir ...
