find out what table a stored procedure updates,inserts to, modifies
I want to be able to be able to filter the results of this query to in include only SprocName that has an INSERT or Update or Modify statement in them. Is there a way to do that? I was tasked with finding out what table each stored procedure writes to. Server 2005 btw SELECT DISTINCT QUOTENAME(OBJECT_SCHEMA_NAME (referencing.object_id)) + '.' + QUOTENAME(OBJECT_NAME(referencing.object_id)) AS SprocName ,QUOTENAME(OBJECT_SCHEMA_NAME (referenced.object_id)) + '.' + QUOTENAME(OBJECT_NAME(referenced.object_id)) AS ReferencedObjectName ,referenced.type_desc AS ReferencedObjectType FROM sys.sql_dependencies d INNER JOIN sys.procedures referencing ON referencing.object_id = d.object_id INNER JOIN sys.objects referenced ON referenced.object_id = d.referenced_major_id WHERE referencing.type_desc = 'SQL_STORED_PROCEDURE' AND referenced.type_desc='USER_TABLE' Order BY SprocName,ReferencedObjectName ; Thank you in advance for your help.
FYI that sys.sql_dependencies is on the depreciation list according to MSDN. You should change your code to use
sys.sql_expression_dependencies. It appears this view has a good bit more information than the old one does as well: