Finding Text in SQL Server Stored Procedures

by ira 12. April 2009 20:01

So, I'm sure you have been met with a similar scenario during development. You know the one that you have to rename a column or even drop a column in the database. This can be quite annoying if you are doing stored procedure based data access for your application. Once you change the column on the table, you have to figure out which stored procedures reference the column. They aren't always tough to find most of the time, but sometimes you are dealing with a column that may be referenced in many stored procedures. Well thanks to my boss Cliff's research and knowledge sharing, your search can be as easy as ours!

 

The query:

USE Northwind 
GO 

DECLARE @SearchText AS VARCHAR(50) 
SET @SearchText = 'CustomerID' 

SELECT 
    ROUTINE_NAME, 
    ROUTINE_DEFINITION 
FROM INFORMATION_SCHEMA.ROUTINES 
WHERE ROUTINE_NAME LIKE '%' + @SearchText + '%' 
    OR ROUTINE_DEFINITION LIKE '%' + @SearchText + '%'

 

This query will return all the names and routine definitions of stored procedures that contain certain text. It is not really bound by column names but I needed a true development scenario. Run the query with what you are looking for and presto! All the stored procedures you will need to modify.

 

Hope this helps!

-Ira

kick it on DotNetKicks.com

Tags: ,

Database | SQL

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

IraIra
I'm just another developer from Florida.

 

Sponsors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

All code samples on this website are free for download, use, and modification with no warranty nor any implied warranty. Liscensed by:

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 United States License.