Stored Procedure Searches for Strings

Downloads
50250.zip

I created a stored procedure named sp_ FindReferences.sql, which you can download from the SQL Server Magazine Web site.This stored procedure accepts an input string and searches the syscomments, sysobjects, and syscolumns system tables in the local database for any reference to that the string. The output result set shows all the tables, procedures, views, and other elements that contain the specified input string.

For example, I was recently asked to find out whether we use Province_Code or Province_ID in one of our company's databases. I used sp_FindReferences to perform a quick search. It turns out that the tables contain columns called Province_ID, yet the views to those tables remap the column to Province_Code.

I use sp_FindReferences almost daily. I hope you find this stored procedure useful, too.

Discuss this Article 1

datagod
on Jul 24, 2006
Hey, this is pretty neat. It is like "grep" for SQL.

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.