sys.dm_sql_referenced_entities is a system function of Microsoft SQL Server that allows to get dependencies which an object has. E.g. you can find out what tables and store procedures are used within a body of a stored procedure named ‘dbo.foo’ you are inspecting:
SELECT * FROM sys.dm_sql_referenced_entities('dbo.foo', 'OBJECT')
Unfortunately there is a bug in builds before SQL Server 2008 July CTP inclusively. The nature of bug is if the ‘dbo.foo’ stored procedure contains UPDATE or DELETE statements with aliases they are not resolved.
See more @ connect