列出视图和表之间的所有关系

时间:2017-09-06 09:22:41

标签: sql oracle11g

我需要架构中维护的所有关系的列表。

我派生了以下查询,但它只能显示tabletable的关系,而且我不知道从哪里可以tableview或{来自

的{1}}到view关系信息
view

谢谢

1 个答案:

答案 0 :(得分:1)

这将有助于您(在T-SQL中):

SELECT
    FrK.name 'FK Name',
    tp.name 'Main_Parent table',
    cp.name, cp.column_id,
    tr.name 'Referenced to',
    cr.name, cr.column_id
FROM 
    sys.foreign_keys FrK
INNER JOIN 
    sys.tables tp ON FrK.parent_object_id = tp.object_id
INNER JOIN 
    sys.tables tr ON FrK.referenced_object_id = tr.object_id
INNER JOIN 
    sys.foreign_key_columns fkc ON fkc.constraint_object_id = FrK.object_id
INNER JOIN 
    sys.columns cp ON fkc.parent_column_id = cp.column_id AND fkc.parent_object_id = cp.object_id
INNER JOIN 
    sys.columns cr ON fkc.referenced_column_id = cr.column_id AND fkc.referenced_object_id = cr.object_id

对于Oracle,请查看以下内容:

select table_name 
from all_constraints 
where constraint_type='R' 
  and r_constraint_name in (select constraint_name   
                            from all_constraints
                            where constraint_type in ('P','U')   
                              and table_name='<your table here>');