Text search in Stored Procedures in SQL Server 2005

12,848

Solution 1

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

Solution 2

SELECT DISTINCT o.name AS Object_Name,o.type_desc
FROM sys.sql_modules        m 
INNER JOIN sys.objects  o 
    ON m.object_id=o.object_id
WHERE m.definition Like '%Serach_Text%'

Solution 3

You can search sys.sql_modules. Definition contains the text of procedures. The view contains procedures, views, udfs etc. To restrict yourself to stored procedures you should join with sys.procedure on object_id.

Share:
12,848
Rohit Agarwal
Author by

Rohit Agarwal

I am a programmer based in Seattle, WA.

Updated on July 27, 2022

Comments

  • Rohit Agarwal
    Rohit Agarwal over 1 year

    How do I find a stored procedure containing a certain text? While I understand that the best place to do this kind of searching is through your source control tool, but are there ways to do this in the database?