有時候刪除某張表記錄的時候,會報錯外鍵約束不能刪除。
如果不了解表之間的關系,可以通過以下語句查詢到外鍵是建在哪張表上的:
select * from dba_constraints where constraint_name='xxx' and constraint_type = 'R';
例如:
執行delete from t_bme_task;時報錯:
ORA-02292: integrity constraint (CCSYS.FK_T_BME_TASKRUNRESULT_TASKID) violated - child record found
可以通過執行
select table_name from dba_constraints where constraint_name='FK_T_BME_TASKRUNRESULT_TASKID' and constraint_type = 'R';
查詢出外鍵是建在T_BME_TASKRUNRESULT表上的,先把T_BME_TASKRUNRESULT表刪除,就可以刪除 t_bme_task表記錄了。