TSQL - Search in stored procedures

SQLSQL Server

Please contribute by voting. Thanks!
3
Here are three different techniques of how you search for text in stored procedures in Microsoft SQL Server (TSQL):

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

SELECT OBJECT_NAME(id) 
    FROM SYSCOMMENTS
    WHERE [text] LIKE '%Foo%'
    AND OBJECTPROPERTY(id, 'IsProcedure') = 1
    GROUP BY OBJECT_NAME(id)

SELECT OBJECT_NAME(object_id)
    FROM sys.sql_modules
    WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1
    AND definition LIKE '%Foo%'
Be aware routine_definition is cropped at 4000 chars just in case you have a long procedure, use the OBJECTPROPERTY-method in such cases.

Article created: Aug 1 '15.

Your comment

You need to sign up / log in to comment this article

Author

Created by Robert Bengtsson [126] Aug 1 '15

Share article

Do you know about

Domain-driven Design (DDD)?

Write an article