Custom Search
Logiclabz
  • Home
  • Sql Server
  • Search text/string|Find keyword in Sql Server Function and Procedure

Search text/string|Find keyword in Sql Server Function and Procedure

  

To find a text or string or keyword across all function and procedure in sql server 2005 using INFORMATION_SCHEMA.ROUTINES & SYS.SQL_MODULES
Option1:

select * from INFORMATION_SCHEMA.ROUTINES
Provides all the details of user-defined Function and Procedure in current database.
By using "ROUTINE_DEFINITION" column in "INFORMATION_SCHEMA.ROUTINES" we can search for any text in all function and procedure
Sample to get List of stored procedures and function that used particular table. i.e to search for table name "testtable" in all function and procedure
we can do
select ROUTINE_NAME, ROUTINE_DEFINITION from 
INFORMATION_SCHEMA.ROUTINES where ROUTINE_DEFINITION like '%testtable%'

Option2 (Recommended):
To search for table name "testtable" using sys.sql_modules
select * from sys.sql_modules where definition like '%test%'

Option 2 would most recommended as INFORMATION_SCHEMA.ROUTINES has only first 8000 characters of sql code but sys.sql_modules stores full code.



  


Leave a reply


Comments

  • Ram says:
    Dec 22, 10

    Thanks, this has saved lot of my time

  • Kamal Sukla says:
    Mar 26, 12

    Hi, I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of stored procedure and it will help me a lot. Over the internet, I've found some other good article which also explained very well on SQL Stored Procedure.... check this helpful links... http://www.mindstick.com/Blog/200/SQL%20Stored%20Procedure http://msdn.microsoft.com/en-us/library/aa174792%28v=sql.80%29.aspx Thanks Everyone!!



Do you like this post?