SQL 2000: Searching stored procedures for text

Alright...you've inherited a database somewhere along the way, and you're doing your best to optimize performance. You see in profiler traces queries being executed that don't seem to be anywhere in the code for the application you now support.

Could they be tucked away in a stored procedure somewhere? Oh, wait...you see dozens of stored procedures where it could be hiding -- oh, no.

A quick and easy means of searching through stored procedures can be done using the following in query analyzer:

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%text to search for%'
AND ROUTINE_TYPE='PROCEDURE'

Simply substitute "text to search for" with what you're hoping to find, run the query, and hopefully you'll be rewarded with the culprit procedure(s) you're trying to track down. There are other means of doing this, of course, however this quick/easy routine will often suffice.

No comments: