Please disable your adblock and script blockers to view this page
 

Sql Server Query to Search any Text in All Stored Procedures, Views and Functions

Introduction: In this article I am going to explain How to find any text/string in all stored procedures or views or user defined functions.


Description:  While working with sql server database it may be required to search for specific text in all stored procedures, view or functions for many reasons. For example we can list all the stored procedure where the specified table is being used or we can even search for any column name in all stored procedures, views and functions to check their dependency.

 Implementation: Let’s write a query to get the desired result

Let's try to search text 'Email'

DECLARE @searchText NVARCHAR(100)='Email'
--Search the text ‘Email’ in sp, view and functions
SELECT DISTINCT S.NAME AS [Schema],O.NAME AS [Object Name],O.TYPE_DESC AS [Type]
FROM SYS.SQL_MODULES M INNER JOIN SYS.OBJECTS O ON M.OBJECT_ID=O.OBJECT_ID
INNER JOIN SYS.SCHEMAS S ON O.SCHEMA_ID=S.SCHEMA_ID WHERE M.DEFINITION
LIKE '%' + @searchText + '%' ORDER BY S.NAME

Note: Pass any table name or column name or any text in @searchText variable to search in all stored procedures, views and user defined functions

Result
Schema
Object
Type
dbo
fnCheckEmailDuplicacy
SQL_SCALAR_FUNCTION
dbo
spEmployeeData
SQL_STORED_PROCEDURE
dbo
spSaveEmployeeDetails
SQL_STORED_PROCEDURE
dbo
vwEmployeeDetails
VIEW

 Now over to you:
A blog is nothing without reader's feedback and comments. So please provide your valuable feedback so that i can make this blog better and If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linkedin and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates. 
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon