Wednesday, October 3, 2012

What stored procedures touch a given table in MSSQL?

Bradley Estep showed me this trick today for fishing for something that touches something else in a database:

DECLARE @Search varchar(255)
SET @Search='
SOMETHINGTOMATCHON'
SELECT DISTINCT
o.name AS Object_Name,o.type_desc
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id=o.object_id
WHERE m.definition Like '%'+@Search+'%'
ORDER BY 2,1

 
 

I fed in the name of a table and was informed of the one stored procedure (in over one hundred) that touched the table in question.

No comments:

Post a Comment