標籤:oracle 資料庫 違反完整約束條件 報錯 外鍵
怎樣查外鍵建在哪個表上
有時候刪除某張表記錄的時候,會報錯外鍵約束不能刪除。
如果不瞭解表之間的關係,可以通過以下語句查詢到外鍵是建在哪張表上的:
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‘;
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/72/DD/wKiom1XuuRyClJ_RAAEwKuMG-qI752.jpg" title="QQ圖片20150908183110.png" alt="wKiom1XuuRyClJ_RAAEwKuMG-qI752.jpg" />
例如:
執行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表記錄了。
本文出自 “技術成就夢想” 部落格,請務必保留此出處http://pizibaidu.blog.51cto.com/1361909/1692857
Oracle怎麼查外鍵建在哪個表上