码迷,mamicode.com
首页 > 数据库 > 详细

Oracle怎么查外键建在哪个表上

时间:2015-09-08 20:22:32      阅读:168      评论:0      收藏:0      [点我收藏+]

标签: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‘;


技术分享


例如:

执行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怎么查外键建在哪个表上

标签:oracle   数据库   违反完整约束条件   报错   外键   

原文地址:http://pizibaidu.blog.51cto.com/1361909/1692857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!