如何查找子表的根表?

时间:2014-03-24 10:50:33

标签: oracle

如何查找子表的Root表?

例如: -

 I have 26 tables A,B,C ...Z. I need to find the indirect relation for particular table

 B has relation with  A
 C has relation with B

 If i will give the table_name like c, it will come to A(indirect relation)

1 个答案:

答案 0 :(得分:1)

您可以尝试在user_constraints

上使用分层查询

PKconstraint_type = 'P'

FKconstraint_type = 'R',并通过r_constraint_name

与主键相关联

沿着这条线的某些东西可能有效(未经测试)

select  table_name 
from    user_constraints 
start with 
    table_name = 'x' 
    and constraint_type = 'P' 
connect by r_constraint_name = prior constraint_name 
    and prior constraint_type = 'R'