在更新表的主键字段或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的更多相关文章

  1. 修复Magento SQLSTATE[23000]: Integrity constraint

    magneto在意外情况下报错Magento SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry,出现这个问题最 ...

  2. 报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'

    在提交注册信息的时候报错:SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key ' ...

  3. 关于 Oracle DB CONSTRAINT约束的一些SQL ORA-02292: integrity constraint violated

    ALTER TABLE table_name DISABLE CONSTRAINT constraint_name; select * from all_constraints where owner ...

  4. Oracle数据库出现[23000][2291] ORA-02291: integrity constraint (SIMTH.SYS_C005306) violated异常

    参考链接 这个异常发生在往中间表中插入数据时,这时出现异常是因为关联的某个表没有插入数据,所以给没有插入数据的关联表插入数据,再给中间表插入数据此时异常就会解决.

  5. 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字段设置自增

  6. SQL基础--> 约束(CONSTRAINT)

    --============================= --SQL基础--> 约束(CONSTRAINT) --============================= 一.几类数据完 ...

  7. SQL Server - 约束 CONSTRAINT

    总结 约束放置在表中,以下五种约束: NOT NULL 非空约束C 指定的列不允许为空值 UNIQUE 唯一约束U 指定的列中没有重复值,或该表中每一个值或者每一组值都将是唯一的 PRIMARY KE ...

  8. constraint、index、view(day04)

    回顾: 1.sql99中的表连接 select 字段列表 from 左表 {[inner]|{left|right|full} [outer]} join 右表 on 关联条件; 集合操作 union ...

  9. ocp 1Z0-042 1-60题解析

    1. Because of a power outage,instance failure has occurred. From what point in the redo log does rec ...

随机推荐

  1. js实现css3的过渡,需要注意的一点(浏览器优化)

    大部分浏览器对元素几何改变时候的重排做了优化.据说是这样子,一定时间内本应多次重排的改变,浏览器会hold住,仅一次重排.其中如果使用分离的一步处理过程,例如计时器,依然多次重排.例如,当我们应用tr ...

  2. Kafka到Hdfs的数据Pipeline整理

    作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 找时间总结整理了下数据从Kafka到Hdfs的一些pipeline,如下 1> Kafka ...

  3. spring boot启用tomcat ssl

    首先要生成一个keystore证书.参考:Tomcat创建HTTPS访问,java访问https,ssl证书生成:cer&jks文件生成摘录,spring-boot 这里复现一下完整过程: 安 ...

  4. ADO.net 更新和插入数据 遇到null 执行不成功

    首先交代下背景,遇到一个问题:SqlCommand新增记录时,参数为null时,运行并不报错,只是返回(0),也就是更新失败. 在用C#往数据库里面插入记录的时候, 可能有的字段我们并不赋值(有可能是 ...

  5. uploadify上传错误:uncaught exception: call to startUpload failed原因

    这个不是什么tab的问题,而是可能有多个上传的div或者input(含有相同的name或者ID)导致的 如果有两个不同的上传按钮,那么他们的name,id要设置得不一样. <div id='to ...

  6. 20款jQuery 的音频和视频插件

    分享 20 款jQuery的音频和视频插件 Blueimp Gallery: DEMO || DOWNLOAD Blueimp gallery 主要为移动设备而设计,同时也支持桌面浏览器.可定制视频和 ...

  7. ASP.Net MVC Action重定向跳出Controller和Area

    1.重定向方法简介 [HttpPost] public ActionResult StudentList( string StudName, string studName, DateTime Bir ...

  8. ASP.NET Core 开发-中间件(Middleware)

    ASP.NET Core开发,开发并使用中间件(Middleware). 中间件是被组装成一个应用程序管道来处理请求和响应的软件组件. 每个组件选择是否传递给管道中的下一个组件的请求,并能之前和下一组 ...

  9. [示例] Firemonkey 不规则按钮实做

    利用 Firemonkey 控件的组合及可塑性,可以做出千变万化的效果及功能,下面展示一个不规则按钮的实做: 效果图: 实做方法: 开一个新工程 Multi-Device Application 放一 ...

  10. InteliJ Shortcuts

    Open your browser with documentation for the element at the editor's caret Press Shift+F1 (View | Ex ...