Thursday, 19 September 2013

Dependency Findings for Objects

SELECT ReferencingObjectType = o1.type, ReferencingObject = SCHEMA_NAME(o1.schema_id)+'.'+o1.name, ReferencedObject = SCHEMA_NAME(o2.schema_id)+'.'+ed.referenced_entity_name, ReferencedObjectType = o2.type FROM sys.sql_expression_dependencies ed INNER JOIN sys.objects o1 ON ed.referencing_id = o1.object_id INNER JOIN sys.objects o2 ON ed.referenced_id = o2.object_id WHERE o1.type in ('P','TR','V', 'TF') ORDER BY ReferencingObjectType, ReferencingObject -- Method 1: Using sp_depends sp_depends 'dbo.First' GO -- Method 2: Using information_schema.routines SELECT * FROM information_schema.routines ISR WHERE CHARINDEX('dbo.First', ISR.ROUTINE_DEFINITION) > 0 GO -- Method 3: Using DMV sys.dm_sql_referencing_entities SELECT referencing_schema_name, referencing_entity_name, referencing_id, referencing_class_desc, is_caller_dependent FROM sys.dm_sql_referencing_entities ('dbo.First', 'OBJECT'); GO