Oracle怎麼查外鍵建在哪個表上

來源:互聯網
上載者:User

標籤: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怎麼查外鍵建在哪個表上

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.