65.9K
CodeProject is changing. Read more.
Home

How to Find a Text in SQL Server Stored Procedure

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.40/5 (4 votes)

Jun 30, 2012

CPOL
viewsIcon

52900

This is an alternative for "Find all Stored Procedures having a given text in it"

Introduction

This article describes How to find a Text in Stored Procedure (Checked on SQL Server 2008)

Background

Need to delete or rename a Column Name in Table? 100's of Stored Procedures? Running short on time? Constraints may save you by generating an warning but Stored Procedure Won't!!!

Here is an awesome Trick that may save your time!!!

This applies to non encrypted stored procedues only.

  • Open SQL Server Management Studio
  • Make sure that you have permission to access the database objects
  • Select the Database which has Stored Procedure in which you need to find Text
  • Click on New Query
  • Below query searches for Text Product and Order [You can use AND or OR and more]

Using the code

SELECT Name as [Stored Procedure Name]
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%Product%'
AND OBJECT_DEFINITION(OBJECT_ID) LIKE '%Code%'

Screen Shot

I am working on Find and Replace version of above example once done will post here. Enjoy

This article was posted on my blog http://www.smartcodar.com/content.php?124-How-to-Find-a-Text-in-SQL-Server-Stored-Procedure added here with some enhancement