>Search Text Used in Store Procedure, Functions or Views in a Database


To search a specific text in all store procedures and functions is common task. It can be achieved by following simple query.

SELECT sys.schemas.name +‘.’+OBJECT_NAME(id)

FROM syscomments INNER JOIN sys.objects ON syscomments.id = sys.objects.object_id
INNER JOIN sys.schemas ON sys.objects.schema_id = sys.schemas.schema_id
AND (OBJECTPROPERTY(id, ‘IsProcedure’) = 1
      OR OBJECTPROPERTY(id, ‘IsScalarFunction’) = 1
      OR OBJECTPROPERTY(id, ‘IsView’) = 1)
GROUP BY sys.schemas.name +‘.’+OBJECT_NAME(id)

Posted on August 25, 2009, in TSQL Tips n Tricks. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: