Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


A Search and Replace Script when Moving Objects from Prod to Test


A Search and Replace Script when Moving Objects from Prod to Test

Author
Message
bkubicek
bkubicek
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2568 Visits: 765
Comments posted to this topic are about the item A Search and Replace Script when Moving Objects from Prod to Test
jwalsh84
jwalsh84
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 185
Sigh...the ideas we need to come up with sometimes to make things easier. Thanks for the post Ben.

Thankfully MS added Synonyms to SQL Server 2005 to make this process easier for everyone.

-James
pbarbin
pbarbin
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 349
Thanks for the article. I had to do a similar thing for our development and test environment. We have two databases in production that have views that point to the other database. Therefore, if we wanted to run 2 separate copies of these databases, we'd run into hardcoded names in the procedural code. So I wrote a similar script to make the changes.

FYI, I used the Sys.Sql_Modules catalog view instead of sp_helptext.
Aaron N. Cutshall
Aaron N. Cutshall
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1623 Visits: 967
We have a similar situation using SS2005, however we use synonyms. When I worked on SS2000, I used linked databases to provide a layer of abstraction.


"...when ye are in the service of your fellow beings ye are only in the service of your God." -- Mosiah 2:17
pbarbin
pbarbin
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 349
I agree that there are better solutions, this script helps you when you have a legacy system that you didn't design. We all have those.

Btw, be careful with the replace command. If you have "CREATE TABLE" statements in your stored procedures, this will change them to "ALTER" table statements.
I solved this by finding the words CREATE PROCEDURE, CREATE PROC, CREATE TRIGGER, CREATE FUNCTION, etc with several variations (like 2 and 3 spaces between the words -- remember I didn't write these!). Regular expressions might be a better solution, but mine works.

I made sure that my script replaced all known variations in production until the changed rows matches the number of procedures in production.
bkubicek
bkubicek
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2568 Visits: 765
Hey James, glad you liked the article. I was pretty happy when I figured this out. I had been thinking about a solution to this for some time. It was nice when I finally figured one out.
Ben
bkubicek
bkubicek
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2568 Visits: 765
Thanks for your suggestions on the replace. I did feel that part of the code was a little weak. Perhaps your suggestions will be in version two of this script.
Ben
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22724 Visits: 18261
Ben,
Thanks for the article. I have to agree with the others, sometimes the hoops we jump through (to make our job a little easier) are astounding. Nice solution.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

bkubicek
bkubicek
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2568 Visits: 765
Hey Jason,

I am glad you liked the article. By the way I like your sqlservercentral name. CirquedeSQLeil is very clever. I have seen their show, it was enjoyable.

Ben
SQLRNNR
SQLRNNR
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22724 Visits: 18261
bkubicek (2/3/2010)
Hey Jason,

I am glad you liked the article. By the way I like your sqlservercentral name. CirquedeSQLeil is very clever. I have seen their show, it was enjoyable.

Ben


I have yet to see one of their shows "live." I like very much what they do/achieve. I thought it was fitting with location and job.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search