Saturday, August 3, 2013

Finding Dependent Tables from Stored Procedures

select distinct object_name(referencing_id) SpName,isnull(sd.referenced_schema_name,'dbo')referenced_schema_name,sd.referenced_entity_name from sys.sql_expression_dependencies sd


LEFT JOIN sys.objects obj ON obj.object_id=sd.referenced_id

 where referencing_id in (select object_id from sys.objects

            where name like '%Agree%' and type='P'