Can database references be replaced during deployment?
a.higgins
Posts: 90 Bronze 2
in SQL Compare
My team currently follows an environment deployment process that places our development, test, and Production databases on separate servers. Within our current loads, we often have scripts that collect information from multiple databases, and merge it into a single target, as follows:
USING
(
SELECT Fields
FROM
StagingDatabase.StagingTable
INNER JOIN
OtherStagingDatabase.StagingTable ON
Condition
) AS Source
I've been asked to evaluate a scenario where our development and test databases would be co-located on a single server, with a suffix denoting which "environment" a database belongs to, e.g., StagingDatabase_DEV and StagingDatabase_QA.
Under that scenario, on the development database the load script above would need to look like this:
MERGE DataWarehouseTable AS Target
USING
(
SELECT Fields
FROM
StagingDatabase_DEV.StagingTable
INNER JOIN
OtherStagingDatabase_DEV.StagingTable ON
Condition
) AS Source
OK so far as it goes, but the same code on the QA server couldn't keep the _DEV references, so it would need to look like this:
My question: is this possible? Or would using the tool result in it seeing differences everywhere, and creating deployment scripts that need to be manually edited after-the-fact to replace database references?USING
(
SELECT Fields
FROM
StagingDatabase_DEV.StagingTable
INNER JOIN
OtherStagingDatabase_DEV.StagingTable ON
Condition
) AS Source
OK so far as it goes, but the same code on the QA server couldn't keep the _DEV references, so it would need to look like this:
MERGE DataWarehouseTable AS Target
USING
(
SELECT Fields
FROM
StagingDatabase_QA.StagingTable
INNER JOIN
OtherStagingDatabase_QA.StagingTable ON
Condition
) AS Source
So, when I use SQL Compare to generate a deployment script, I'd need to
USING
(
SELECT Fields
FROM
StagingDatabase_QA.StagingTable
INNER JOIN
OtherStagingDatabase_QA.StagingTable ON
Condition
) AS Source
So, when I use SQL Compare to generate a deployment script, I'd need to
- Ignore those differences during the Compare operation, and
- Replace the references to _DEV when generating deploy script
Tagged:
Answers
You need to pre-create the target database and the name of the target database is largely irrelevant once you compare and deploy (assuming you don't have for example Stored Procedures which use three-part name references)
Product Support Engineer
Redgate Software Ltd
Please see our Help Center for detailed guides on how to use our tools
A workaround that can be used is to use synonyms: this means that you can use an unchanged Stored Procedure regardless of the database, you can then pre-create the synonyms differently on each database and use a SQL Compare Filter to exclude synonyms from the comparison.
Product Support Engineer
Redgate Software Ltd
Please see our Help Center for detailed guides on how to use our tools