ORA-02292: integrity constraint (BLDBANK.F_YXDH) violated - child record found

今天在做节能项目一对多关联platform_corporation表时,在platform_corporation表中发现一条只有主键其他均为空的数据,删除该条数据是会报如标题所示错误:

查看前台装置列表不会影响,但是本着数据洁癖的心理,网上查找资料想干掉它,通过如下方法:

经常我们在删除DB记录时,会为外键关联而无法删除数据感到苦恼。这里个人经常用到的一个方法就是,先让关联主键失效,然后再删除数据,数据删除完成后,再让其主

键生效,这样很好的解决了删除级联数据难的问题。

 第一步:让主键失效:alter table table_name disable primary key cascade;

 

第二步:删除数据:delete table_name;

第三步:让主键生效:alter table table_name enable primary key;

无效!

继续查找方法:

发现:

删除数据时遇到:

ORA-02292: 违反完整约束条件 (用户名.约束名) - 已找到子记录

ORA-02292: integrity constraint (BLDBANK.F_YXDH) violated - child record found

关于这个错误,oracle官方解决方法是: Error: orA-02292: integrity constraint <constraint name> violated - childrecord found
Cause: You tried to Delete a recordfrom a parent table (as referenced by a foreign key), but a record in the childtable exists.
Action: The options to resolve this oracle error are: This error commonly occurs when you have a parent-child relationshipestablished between two tables through a foreign key. You then have tried todelete a value into the parent table, but the corresponding value exists in thechild table. To correct this problem, you need to update or delete the value into the childtable first

解决步骤

1、  找出父表(需要删除表数据的表)所属用户,然后用此用户登录数据库(若已经使用此用户登录则省略此部)

 

select*fromall_tableswheretable_name=upper('blood_test')    blood_test是父表、要删除数据的表

2、  根据约束名查找子表(引用父表字段作为外键的表)

select*fromuser_constraints e where e.constraint_name='F_YXDH'  F_YXDH是报错时的约束名

3、  根据条件将子表中的数据删除,然后再删除父表中的记录

发现该记录关联着platform_expert表中的一条记录,将该条记录删除后,platform_corporation表中的空记录就被干掉了!!

该方法完美解决问题!!

 

posted on 2014-09-12 16:48  痞子斑斑  阅读(1584)  评论(0编辑  收藏  举报