Solved

Global search and replace

Posted on 2011-03-25
5
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

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 40

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 40

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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