Quickest/Easiest way to use Search/Replace through all stored procedures

sql, sql-server, sql-server-2008

Solution

To search: if you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).

It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use?

This tool doesn't support replacing text, however - but even just being able to find all the relevant stored procedures (or other DB objects) is very helpful indeed!

Problem

Actually, this is a 2 part question. Is it possible to use some sort of functionality to search through every stored procedure for a string and possibly replace it, like a standard Find/Replace function? If you have all your stored procedure code include the full database path like this `[db1].[dbo].[table1]` and you change the database name to `[db2]` is there a way for SQL Server to automatically update all the code from `[db1]` tables to `[db2]`? Or does it have to be done manually?

Original source