我需要架构中维护的所有关系的列表。
我派生了以下查询,但它只能显示table
到table
的关系,而且我不知道从哪里可以table
到view
或{来自
view
关系信息
view
谢谢
答案 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>');