Counter of Festivals

Ashok Blog for SQL Learners and Beginners and Experts

Monday, 13 April 2015

How to get Reference or Referenced Objects through sys.dm_sql_referencing_entities and sys.dm_sql_referenced_entities in SQL 2008?

Result
Object does not reference any object, and no objects reference it.
Object does not reference any object, and no objects reference it.
Both the sp_depends statements in the above script are not returning the referencing/referenced objects list. For example the stored procedure dbo.GetEmployeeDetails is referring the Employee table but sp_dpends is not providing this dependency information. Reason for this is: Stored procedure dbo.GetEmployeeDetails which is refereeing to this Employee table is created first and then the employee table in other words we call it as deferred resolution.
Solution to this problem is to use the DMV’s: sys.dm_sql_referencing_entities and sys.dm_sql_referenced_entities. Now let us check whether we are able to get the expected results using these DMV’s:
SPDependsAlternative
Note: These two DMV’s are introduced as a part of Sql Server 2008. So this alternate solution works for Sql Server version 2008 and above.

No comments:

Post a Comment