删除数据时遇到:
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*from all_tableswhere table_name=upper('blood_test') blood_test是父表、要删除数据的表
2、 根据约束名查找子表(引用父表字段作为外键的表)
select*from user_constraintse where e.constraint_name='F_YXDH' F_YXDH是报错时的约束名
3、 根据条件将子表中的数据删除,然后再删除父表中的记录
备注
altertable 表名 disable constraint 约束名;
altertable 表名 enable constraint 约束名;
可以禁用约束,然后删除数据,但是再重启约束的时候也会有报错,若是删除表的操作可以先禁用约束然后再启用
当尝试删除具有外键约束的Oracle数据库中父表的记录时,可能会遇到ORA-02292错误。此错误表明在子表中存在相关记录。解决这个问题的步骤包括:确定父表和子表,然后先删除子表中的相关记录,最后删除父表中的记录。如果需要,可以暂时禁用约束来完成操作。
6013

被折叠的 条评论
为什么被折叠?



