Find Any String in Any SQL Code in Any Database

Find.sql can save you hours of frustration when you need to find a specific piece of code

Downloads
99466.zip

Have you ever needed to quickly find all the stored procedures that contain a certain field? Have you ever needed to find some code you wrote a while ago but have forgotten the name of that code? Have you ever needed to find all the code on the server that references a particular table? To find such items, you could purchase database documentation software—or you could use Find.sql.

Find.sql is the most popular piece of code I’ve ever written. This stored procedure finds any string in any type of SQL code (e.g., view, procedure, function) in any database on a server without hurting the server’s overall performance. Find.sql won’t search for strings in the database’s data, however. If you need that capability, check out the table-searching script at www.users.drew.edu/skass/sql/SearchAllTables.sql.txt.

I named the stored procedure Find so its name is easy to remember. Find.sql is also easy to use. You just need to download the stored procedure by clicking the 99466.zip hotlink above. On the server you want to search, you call the stored procedure by typing

 Find 'mystring'

where mystring is the string you want to search for. The stored procedure will search for that string in all the databases on your server and return a list of the objects that contain it. As Figure 1 shows, the list is ordered by database. It tells you the name of the object as well as the type of object in which your string has been found. It uses notations such as P for procedure, FN for function, and V for view for the object type.

I wrote Find.sql for SQL Server 2000, but it should work on SQL Server 6.5 through SQL Server 2008. Many DBAs and developers are using it to make their jobs easier. Play around with Find.sql to see what it can do—it could save you hours of frustration when you need to find a specific piece of code.

—Michael Berry, senior DBA, Ohio Public Employees Retirement System

Discuss this Article 2

dystarry
on Jul 31, 2008
in case of sql server 2005 and 2008 "sys.sql_modules" category view is more useful than "syscomments" system table. in addition [syscomments].[text] column size is too small to store the source code of big(?) SPs, UDFs, Views. in this case source code is devided into multiple rows and your code might not work properly...
yangwulong1978
on Aug 6, 2008
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '00293'.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Mike Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
Vision road sign
May 6, 2013
blog

Cheaters Never Win, Even in TPC Benchmarks

In this portion of the series on database benchmarking, I want to tell you about one of my favorite aspects of the TPC benchmarks – CHEATING....More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.