我试图从数据库中删除一条记录,但是ORACLE声称"违反了完整性约束 - 找到了儿童记录"。
如果我试图找到这个子记录,它在DB中就不存在了。
任何人都知道如何解决这个问题?
SQL> delete from AMZ_SERVCO where ID_SERVCO = 447;
delete from AMZ_SERVCO where ID_SERVCO = 447
*
ERROR at line 1:
ORA-02292: integrity constraint (AMAZONIA.FK_AMZ_FRNQIA_PA_AMZ_SERVCO) violated - child record found
SQL> select table_name from all_tab_columns where column_name='ID_SERVCO';
TABLE_NAME
------------------------------
AMZ_DESCTO_PO_SERVCO_APLCAO
AMZ_DESCTO_PO_SERVCO
BKP151207_AMZ_ARQVO_DESCTO
BKP_ARQVO_DESCTO
AMZ_SERVCO_PO
AMZ_SERVCO_PA
AMZ_SERVCO
AMZ_FRNQIA_PO_SERVCO
AMZ_DESCTO_PO
AMZ_CATEGR_PO
AMZ_CATEGR_PA
TABLE_NAME
------------------------------
AMZ_BONUS_PO
AMZ_ASSTUR_PO
AMZ_ASSTUR_PA
AMZ_ARQVO_SERVCO
AMZ_ARQVO_DESCTO
AMZ_APA_PO
AMZ_APA_PA
AMZ_FRNQIA_PA_SERVCO
AMZ_EXPSAO_ENTDDE_OPRDRA
20 rows selected.
SQL> select * from AMZ_EXPSAO_ENTDDE_OPRDRA WHERE ID_SERVCO = 447;
select * from AMZ_FRNQIA_PA_SERVCO WHERE ID_SERVCO = 447;
select * from AMZ_APA_PA WHERE ID_SERVCO = 447;
select * from AMZ_APA_PO WHERE ID_SERVCO = 447;
select * from AMZ_ARQVO_DESCTO WHERE ID_SERVCO = 447;
select * from AMZ_ARQVO_SERVCO WHERE ID_SERVCO = 447;
select * from AMZ_ASSTUR_PA WHERE ID_SERVCO = 447;
select * from AMZ_ASSTUR_PO WHERE ID_SERVCO = 447;
select * from AMZ_BONUS_PO WHERE ID_SERVCO = 447;
select * from AMZ_CATEGR_PA WHERE ID_SERVCO = 447;
select * from AMZ_CATEGR_PO WHERE ID_SERVCO = 447;
select * from AMZ_DESCTO_PO WHERE ID_SERVCO = 447;
select * from AMZ_FRNQIA_PO_SERVCO WHERE ID_SERVCO = 447;
select * from AMZ_SERVCO WHERE ID_SERVCO = 447;
select * from AMZ_SERVCO_PA WHERE ID_SERVCO = 447;
select * from AMZ_SERVCO_PO WHERE ID_SERVCO = 447;
select * from BKP_ARQVO_DESCTO WHERE ID_SERVCO = 447;
select * from BKP151207_AMZ_ARQVO_DESCTO WHERE ID_SERVCO = 447;
select * from AMZ_DESCTO_PO_SERVCO WHERE ID_SERVCO = 447;
select * from AMZ_DESCTO_PO_SERVCO_APLCAO WHERE ID_SERVCO = 447;
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
ID_SERVCO NM_SERVCO ID_TP_SERVCO ID_TP_CATEGR
----------------------------------------------------------------- ------------ ------------
447 eClaro DDD Nacional 5 0
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
no rows selected
SQL>
答案 0 :(得分:1)
是的,您需要在所有约束列表中查找违反的约束:
SELECT r_owner, r_constraint_name
FROM all_constraints
WHERE owner='AMAZONIA'
AND constraint_name='FK_AMZ_FRNQIA_PA_AMZ_SERVCO';
这是父表的主键或唯一键的名称。要查找它的列,您可以使用:
SELECT column_name
FROM all_cons_columns
WHERE owner = xxx
AND constraint_name = yyy;
答案 1 :(得分:0)
听起来你可能有另一个你不知道的外键:尝试this solution获取所有外键的列表。对于像这样的复杂系统,我尝试包含[IsActive]布尔列 - 而不是删除可能有子节点的记录,只需将其标记为非活动状态。 HTH!