Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Script to find text in stored procedures

By Doug Elwood,

This is a simple script that when used by command-line OSQL/ISQL can help you locate a stored procedure.

How many times have you been looking for stored procedure code and could not find it?  This is a simple method to locate lost code.

When you manage many database servers this can become a common problem.  The scenario is familiar, you can recall working on a stored procedure, but not where it was located.

First the really easy part, create a file that contains each of your servers.  It should be a very basic text file like the following:
(dbservers.txt)
Server1
Server2
Server3

Create your script using the text in the script box and save it as a .sql file.  For this example, I used sqlfile.sql.  Please remove the comments first, they are not needed.

After saving the T-SQL script, open a command-line window (DOS Command Prompt) and type the following at the prompt:

FOR /F %s in (dbservers.txt) DO @OSQL -S%s -E -i sqlfile.sql >> search.txt

This will loop through all database servers in your file and search for the text you provide as "searchtext".

When you manage many SQL Servers this is a very handy tool to use.  Keep in mind you can use this same method to search for job steps, table names, views, functions, etc.

Total article views: 1785 | Views in the last 30 days: 2
 
Related Articles
FORUM

Scripting Stored Procedures

Scripting Stored Procedures

ARTICLE

Setting SQL Server Default Locations

How to set the default locations for backups, data files, and log files in SQL Server.

SCRIPT

move MDF or LDF files to new location

This stored procedure move the LDF or MDF to a new location.

FORUM

SQL Server table backups location

SQL Server table backups location

FORUM

Stored Procedure (or) SQL Script Output to Text File

Stored Procedure (or) SQL Script Output to Text File

Tags
miscellaneous    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones