July 20, 2006 10:20 PM

Stored Procedure Searches for Strings

Rating: (0)
SQL Server Magazine
InstantDoc ID #50250

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.

Add a Comment

Hey, this is pretty neat. It is like "grep" for SQL.

datagod 7/24/2006 11:44:58 AM


You must log on before posting a comment.

Are you a new visitor? Register Here