Search Stored Procedure Code in SQL Server

Every now and then, I need to find all stored procedures containing some string. Here’s how to do that:

SELECT
ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%foobar%' AND ROUTINE_TYPE='PROCEDURE'

Replace “foobar” with the string to search for.