Thursday, December 11, 2008

Search for Text + String within a Stored Proc in SQL

I was searching for a Query in MS SQL for searching a string inside the available stored procedure, and found this query.


Query with the Objects and search with the content(definition) of the stored proc

select o.name as [StoredProc] from sys.objects o
inner join
sys.sql_modules m
on
o.object_id = m.object_id
where
m.definition like '%[String to be Searched]%'

or we can directly query into the Sys.Procedures

SELECT Name FROM sys.procedures
WHERE
OBJECT_DEFINITION(OBJECT_ID) LIKE '%%'
AND
OBJECT_DEFINITION(OBJECT_ID) LIKE '%%'