怎樣查外鍵建在哪個表上
有時候删除某張表記錄的時候,會報錯外鍵限制不能删除。
如果不了解表之間的關系,可以通過以下語句查詢到外鍵是建在哪張表上的:
select * from dba_constraints where constraint_name='xxx' and constraint_type = 'R';
例如:我的程式日志中報如下錯誤,我要知道外鍵是在那個表上.
2015-09-08 18:28:18 [ main:261597003 ] - [ ERROR ] java.sql.SQLException: ORA-02291: 違反完整限制條件 (IRP.FK66EC57AF5158B9FB) - 未找到父項關鍵字
select * from dba_constraints where constraint_name='FK66EC57AF5158B9FB' and constraint_type = 'R';
<a href="http://s3.51cto.com/wyfs02/M00/72/DD/wKiom1XuuRyClJ_RAAEwKuMG-qI752.jpg" target="_blank"></a>
例如:
執行delete from tablename時報錯:
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表記錄了。
本文轉自pizibaidu 51CTO部落格,原文連結:http://blog.51cto.com/pizibaidu/1692857,如需轉載請自行聯系原作者