发布网友 发布时间:2022-04-24 09:51
共3个回答
懂视网 时间:2022-04-08 13:15
--查外键表NC56.CSCI有无对应的主键表 SELECT a.owner, A.TABLE_NAME primary_table_name, A.CONSTRAINT_NAME primary_table_key_name, b.owner, B.TABLE_NAME foreign_table_name, B.CONSTRAINT_NAME foreign_table_foreign_key_name, B.STATUS foreign_table_foreign_key_stat FROM DBA_CONSTRAINTS A, DBA_CONSTRAINTS B WHERE A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME and B.CONSTRAINT_TYPE = 'R' AND b.TABLE_NAME = 'CSCI' and a.owner='NC56' and b.owner='NC56' ORDER BY 1, 2, 3, 4;
--查主键表NC56.CBH有无对应的外键表 SELECT a.owner, A.TABLE_NAME primary_table_name, A.CONSTRAINT_NAME primary_table_key_name, b.owner, B.TABLE_NAME foreign_table, B.CONSTRAINT_NAME foreign_table_foreign_key_name, B.STATUS foreign_table_foreign_key_stat FROM DBA_CONSTRAINTS A, DBA_CONSTRAINTS B WHERE A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME and B.CONSTRAINT_TYPE = 'R' AND a.TABLE_NAME = 'CBH' and a.owner='NC56' and b.owner='NC56' ORDER BY 1, 2, 3, 4;
版权声明:本文为博主原创文章,未经博主允许不得转载。
Oracle数据库中,知道一张表,查询与其有主外键关系的表
标签:
热心网友 时间:2022-04-08 10:23
有时候删除某张表记录的时候,会报错外键约束不能删除。
如果不了解表之间的关系,可以通过以下语句查询到外键是建在哪张表上的:
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表记录了。
热心网友 时间:2022-04-08 11:41
如果不了解表之间的关系,可以通过以下语句查询到外键是建在哪张表上的:
select * from dba_constraints where constraint_name='xxx' and constraint_type = 'R';
例如:我的程序日志中报如下错误,我要知道外键是在那个表上.
2015-09-0818:28:18 [ main:261597003 ] - [ ERROR ] java.sql.SQLException:
ORA-02291: 违反完整约束条件 (IRP.FK66EC57AF5158B9FB) - 未找到父项关键字
select * from dba_constraints where constraint_name='FK66EC57AF5158B9FB' and constraint_type = 'R';