我需要识别与视图关联的所有表格。桅杆视图非常复杂并且具有许多子视图,而这些子视图又通过更多视图连接。
我发现下面的代码说明了父子关系,但我需要明确地显示哪个是视图,哪个是表。有人可以帮助我加强这个吗?
我是否使用type_id或类似xtype ='V',xtype ='TT
的地方 DECLARE @ViewName VARCHAR(MAX);
SET @ViewName = 'MarketAtAGlance';
select * from
(
WITH deps ( parent, child ) AS ( SELECT v.name ,
sed.referenced_entity_name
FROM sys.sql_expression_dependencies sed
INNER JOIN sys.views AS v ON sed.referencing_id = v.object_id
WHERE v.name = ISNULL(@ViewName, v.name)
UNION ALL
SELECT v.name ,
sed.referenced_entity_name
FROM sys.sql_expression_dependencies sed
INNER JOIN sys.views AS v ON sed.referencing_id = v.object_id
INNER JOIN deps ON deps.child = v.name ) SELECT parent ,
child FROM deps ORDER BY parent ,
child;
)
a