Solved

Global search and replace

Posted on 2011-03-25
5
293 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:HLRosenberger
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 35218678
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
 
LVL 39

Expert Comment

by:lcohan
ID: 35218691
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
 
LVL 1

Author Comment

by:HLRosenberger
ID: 35231698
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
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 35233102
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
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 35233369
Thanks. We are on the same page!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question