sql server

Search for keyword in SQL Server Objects

Have you ever had to search for some keyword in a database object code. Here is a piece of sql that will search through the database (not data) for a keyboard :

select DISTINCT  a.name
from sysobjects a (NOLOCK)
join syscomments b (NOLOCK) ON a.id = b.id
where a.type IN (‘P’, ‘TR’, ‘V’, ‘FN’)
and b.text LIKE ‘%cursor%’

This will search through stored procedures, triggers, views and functions defined on the database for the word ‘cursor’.