Search

Thursday, October 27, 2011

sp_depends Stored Procedure

There are many undocumented Stored Procedure in SQL Server. 
sp_depends is one of them. This is a very useful stored procedure. This stored procedure reports the object dependencies in the current database. It shows all objects that depend on the specified object as well as all objects that the specified object depends on.


Syntax
USE AdventureWorks2008R2;
GO
 EXEC sp_depends 'Production.Product'


This SP will be removed from future version of SQL Server. So instead of using this we can use sys.dm_sql_referencing_entities and sys.dm_sql_referenced_entities


Example:

USE AdventureWorks2008R2;
GO
SELECT referencing_schema_name, referencing_entity_name, referencing_id, referencing_class_desc, is_caller_dependent FROM sys.dm_sql_referencing_entities ('Production.Product', 'OBJECT');
GO

USE AdventureWorks2008R2;
GO
SELECT referenced_schema_name, referenced_entity_name, referenced_minor_name, referenced_minor_id, referenced_class_desc FROM sys.dm_sql_referenced_entities ('ddlDatabaseTriggerLog', 'DATABASE_DDL_TRIGGER');
GO

No comments:

Post a Comment