Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find a stored procedure containing <text>?

I need to search a SQL server 2008 for stored procedures containing where maybe the name of a database field or variable name.

like image 929
Gary Kindel Avatar asked Feb 22 '11 14:02

Gary Kindel


People also ask

How do I find Stored Procedures with text in SQL Server?

Using SQL Server Management StudioExpand Stored Procedures, right-click the procedure and then select Script Stored Procedure as, and then select one of the following: Create To, Alter To, or Drop and Create To. Select New Query Editor Window. This will display the procedure definition.

How do I find Stored Procedures?

Using SQL Server Management StudioIn Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand Databases, expand the database in which the procedure belongs, and then expand Programmability. Expand Stored Procedures, right-click the procedure and then click View Dependencies.


2 Answers

SELECT ROUTINE_NAME, ROUTINE_DEFINITION     FROM INFORMATION_SCHEMA.ROUTINES      WHERE ROUTINE_DEFINITION LIKE '%Foo%'      AND ROUTINE_TYPE='PROCEDURE' 

SELECT OBJECT_NAME(id)      FROM SYSCOMMENTS      WHERE [text] LIKE '%Foo%'      AND OBJECTPROPERTY(id, 'IsProcedure') = 1      GROUP BY OBJECT_NAME(id) 

SELECT OBJECT_NAME(object_id)     FROM sys.sql_modules     WHERE OBJECTPROPERTY(object_id, 'IsProcedure') = 1     AND definition LIKE '%Foo%' 
like image 50
Kashif Avatar answered Oct 08 '22 17:10

Kashif


Grab yourself a copy of the free Red-Gate SQL Search tool and start enjoying searching in SQL Server! :-)

enter image description here

It's a great and very useful tool, and YES! it's totally, absolutely FREE for any kind of use.

like image 30
marc_s Avatar answered Oct 08 '22 19:10

marc_s