Moving a script that has a hard-coded server name from test to production
JAlessi
Posts: 3 New member
We have a test environment that contains one sql server with a copy of each of our databases on it. In production we have multiple sql servers each with different DBs on them, so we do a lot of cross server scripting.
When we code in test (because there is only one server) the DBs have names like TestSRV.DB1.dbo.Table1 or TestSRV.DB2.dbo.Table2. When these scripts get productionized the "TestSRV" server name needs to change to the actual production server name for the cross-server call. Is there a way to automate (or simplify) this when productionizing so the developers do not have to go into tested code and make changes for production?
I know we can use find/replace but for large deployments it can be imprecise and sometimes things get missed.
When we code in test (because there is only one server) the DBs have names like TestSRV.DB1.dbo.Table1 or TestSRV.DB2.dbo.Table2. When these scripts get productionized the "TestSRV" server name needs to change to the actual production server name for the cross-server call. Is there a way to automate (or simplify) this when productionizing so the developers do not have to go into tested code and make changes for production?
I know we can use find/replace but for large deployments it can be imprecise and sometimes things get missed.
Tagged:
Answers
Hi @JAlessi
Thank you for reaching out on the Redgate forums.
There isn't a specific process that comes to mind for this using our tools, but perhaps the usage of synonyms in your code may be of use. SQL - Synonyms
If you had two objects 'T1' & 'T2' that you are wanting to reference
On your DEV environment database you could, for example, create the following synonyms:
and on the PROD environment you would create the following:
This would allow you to write code in test that can be executed in production without modification.
Would run on both systems and query different servers
Outside of this it may be necessary to use a bulk rename process where you would have to define what server is used for each object