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
Solved

Global search and replace

Posted on 2011-03-25
5
294 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query 8 51
export sql results to csv 6 39
SQL Insert parts by customer 12 42
Downgrading MS SQL 2008 R2 Enterprise to MS SQL 2005 Standard? 12 64
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 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