HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How can I search the full text of a stored procedure for a value?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storedcanfullthesearchtextvalueprocedureforhow

Problem

I use the following script to search the text of all stored procedures when I want to find specific values.

SELECT ROUTINE_NAME, ROUTINE_TYPE
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE @searchText
ORDER BY ROUTINE_NAME


I recently discovered that ROUTINE_DEFINITION stops after 4000 characters, so some procedures were not getting returned when they should have been.

How can I query the full text of a stored procedure for a value?

Solution

Use one of

  • sys.sql_modules



  • Red Gate SQL Search (free!)



  • OBJECT_DEFINITION



Never use

  • INFORMATION_SCHEMA



  • sys.syscomments

Context

StackExchange Database Administrators Q#41765, answer score: 7

Revisions (0)

No revisions yet.