Global search and replace

Is there a way to do a global search and replace of text within all procs and views?  I want to change the name of a table, for every place it is referenced.
LVL 1
HLRosenbergerAsked:
Who is Participating?
 
lcohanConnect With a Mentor Database AnalystCommented:
Yes, that's what I meant.
You can select and script them all from SSMS including the DROP/CREATE statements into one single file, save that file and keep it safe, do a replace all in that file then save it under different name so you have the originals for rollback plus the updated code then run the new one in your database.
0
 
lcohanDatabase AnalystCommented:
you will have to take and ALTER each object individualy however if they are not encrypted the query below will list you all - just replace table_name below and run it in your db:

select * from sys.syscomments where text like '%table_name%'
0
 
lcohanDatabase AnalystCommented:
oh yeah...and have the list of all objects you could actualy script them all from SQL in one single file and replace all (ctrl-h) works great in that case - hopefully the table_name is not "language" so you get cold hits as well....good luck
0
 
HLRosenbergerAuthor Commented:
How about this for all Views and Procs - I script them out into one large script, make the changes with a text editor, delete all Views and Procs, run the script to restore.
0
 
HLRosenbergerAuthor Commented:
Thanks. We are on the same page!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.