当前位置: 代码迷 >> Oracle管理 >> 怎么根据oracle的主键获取表的关联关系
  详细解决方案

怎么根据oracle的主键获取表的关联关系

热度:94   发布时间:2016-04-24 05:12:58.0
如何根据oracle的主键获取表的关联关系?
不好意思,分数很羞涩,没有太多分可以给。。

使用sql语句能不能根据某个表的主键来查找是否有表的外键与之关联(ps:主键名称和外键名称不一样)?

就是怎么判断一个表是否存在关联表?已知表是主表,想知道它是否有子表,且主表的主键名和子表相应的外键字段名不一定相同。



------解决方案--------------------
可以用toad里面的referential
------解决方案--------------------
select a.constraint_name, a.table_name, b.constraint_name
from user_constraints a, user_constraints b
 where a.constraint_type = 'R'
and b.constraint_type = 'P'
and a.r_constraint_name = b.constraint_name

P 代表主键
R 代表外键

通过关联,能查询到你所想要的一切。
  相关解决方案