How to search all Stored Procedures for a reference

Viewing table dependencies will show you what SP’s depend on the table, but what if you need to find those SP’s which only reference a single field. The following queries will provide you with a list of SP’s which contain the reference you are searching for.

SELECT OBJECT_NAME(id)
FROM syscomments
WHERE [text] LIKE '%look for me%'
AND OBJECTPROPERTY(id, 'IsProcedure') = 1
GROUP BY OBJECT_NAME(id)

or
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%look for me%'
AND ROUTINE_TYPE='PROCEDURE'

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Twitter
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *

*