Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

A Search and Replace Script when Moving Objects from Prod to Test Expand / Collapse
Author
Message
Posted Wednesday, February 3, 2010 12:01 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 1:17 PM
Points: 1,868, Visits: 481
Comments posted to this topic are about the item A Search and Replace Script when Moving Objects from Prod to Test
Post #858419
Posted Wednesday, February 3, 2010 7:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, September 30, 2014 8:22 AM
Points: 1, Visits: 181
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
Post #858691
Posted Wednesday, February 3, 2010 7:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 13, 2012 7:23 AM
Points: 22, 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.

Post #858694
Posted Wednesday, February 3, 2010 8:01 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 22, 2014 11:25 AM
Points: 1,144, Visits: 546
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
Post #858704
Posted Wednesday, February 3, 2010 8:08 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, December 13, 2012 7:23 AM
Points: 22, 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.


Post #858714
Posted Wednesday, February 3, 2010 8:29 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 1:17 PM
Points: 1,868, Visits: 481
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
Post #858739
Posted Wednesday, February 3, 2010 8:32 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 1:17 PM
Points: 1,868, Visits: 481
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
Post #858742
Posted Wednesday, February 3, 2010 12:35 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:51 PM
Points: 17,845, Visits: 15,797
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
Post #858947
Posted Wednesday, February 3, 2010 12:38 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 1:17 PM
Points: 1,868, Visits: 481
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
Post #858951
Posted Wednesday, February 3, 2010 12:47 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:51 PM
Points: 17,845, Visits: 15,797
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
Post #858961
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse