Subscribe to our YouTube Channel for more Videos

Quick way to search within a procedure in SQL Server


There are times when you want to to list out all the stored procedure names that contains certain keyword or search text.

Here’s a simple query that helps you do that.

Quick way to search within a procedure in SQL Server

SELECT OBJECT_NAME(ID) FROM SysComments 
WHERE Text LIKE '%<Search String>%' 
AND OBJECTPROPERTY(id, 'IsProcedure') = 1

Replace the <Search String> with the text that you want to search within all the stored procedures.

Here’s a query that retrieves all the stored procedures that contains the text employee.

SELECT OBJECT_NAME(ID) FROM SysComments 
WHERE Text LIKE '%Employee%' 
AND OBJECTPROPERTY(id, 'IsProcedure') = 1

image

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.