Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Global search and replace

Posted on 2011-03-25
5
Medium Priority
?
299 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

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 …
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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