oracle 查询以查找表关系类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3566565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:22:38  来源:igfitidea点击:

Query to find table relationship types

oracleentity-relationship

提问by Mike

Using Oracle, is there any way I can execute a query to determine what relationship a specific table has with any other tables in my database? I'm fiddling with the all_constraintstable as of now.

使用 Oracle,有什么方法可以执行查询来确定特定表与我的数据库中的任何其他表有什么关系?我现在正在摆弄all_constraints桌子。

回答by Tony Andrews

Yes, you can do this for example:

是的,您可以这样做,例如:

select p.table_name, 'is parent of ' rel, c.table_name
from   user_constraints p
join   user_constraints c on c.r_constraint_name = p.constraint_name
                         and c.r_owner = p.owner
where p.table_name = 'MYTABLE'    
union all
select c.table_name, 'is child of ' rel, p.table_name
from   user_constraints p
join   user_constraints c on c.r_constraint_name = p.constraint_name
                         and c.r_owner = p.owner
where c.table_name = 'MYTABLE' 

回答by Moeb

I think your best bet is trying to extract as much information as you can from the foreign keyconstraints.

我认为最好的办法是尝试从外键约束中提取尽可能多的信息。

Have a look at this articleat Database Journal that explains foreign key data mining in detail.

看一下Database Journal上的这篇文章,它详细解释了外键数据挖掘。