SQL Server trick: finding text in multiple stored procedures
February 26th, 2009 . by LorisSometimes I need to know which stored procedures or views are using a particular table or field.
Most people I’ve seen, when presented with this problem do this the long, boring and potentially error-prone way: opening up each and every stored procedure or view in SSMS and using the good old "Find and replace" tool to find out whether it is using the table or field we’re looking for.
There is, however, a much, much better way to do this, with a simple SQL query. Suppose we want to find out which stored procedure or view uses the table foobar:
SELECT DISTINCT OBJECT_NAME(ID) FROM SYS.SYSCOMMENTS WHERE [TEXT] LIKE '%foobar%'