SQL Server 用SSMS查看依赖关系有时候不准确,明明某个sp中有用到表tohen,查看表tohen的依赖关系的时候,却看不到这个sp
用代码查看方式如下:
--依赖于表tohen的对象
SELECT * FROM sys.dm_sql_referencing_entities('dbo.tohen','OBJECT')
--存储过程sp_tohen依赖的对象
SELECT distinct referenced_entity_name FROM sys.dm_sql_referenced_entities('dbo.sp_tohen','OBJECT') --查看所有对象的依赖关系
SELECT o.name, o.type_desc, p.name as referenced_name, p.type_desc type_desc2
FROM sys.sql_expression_dependencies d
INNER JOIN sys.objects o ON d.referencing_id = o.object_id
INNER JOIN sys.objects p ON d.referenced_id = p.object_id