SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Update 2 databases with 1 script

By Rich Yarger,

This script was developed to manage a pair of databases that were basically the same, but very different in the schema/metadata content. Unfortunately - they both had the same database name, and were in 2 very specific areas (our main SQL Server and a bunch of hardware devices that were running a very watered down version of the database on Embedded Windows, which is basically WinXP and SQL Server 2005 Express). The environment as a whole is on SQL Server 2005 with SP3 (at the time of this offering, SP4 had not been tested for this project, and thus was not a part of any field/dev test).


So essentially - the script works as follows:


- Each section of the UPDATE script has 2 areas. 1 for one database and 1 for the other (specified with the values of 'c%' and 't%' in my example.


- Simply add in your DDL/DML updates in a specific VERSION section that you would like to have identified for that release.


- Whether or not a VERSION release area has content in it or not, your database is going to claim to have received that update. In my example you see 2 sections. This was done for demonstrating how easy it is to simply add another VERSION section, and the logic needed in each.


Please feel free to modify this as you like to make it work specifically for you, as well as better for best coding practices/logic.


I want to thank both Pam Brisjar and Geoff Russell for thier assistance in getting the logic for this put together, correctly.



* * * * *EDIT* * * * *

I unfortunately did not properly include the 2 tables and 1 DML trigger needed for this script to work. Please see the discussion section for those DDL pieces. Thanks, and my apologies.

Total article views: 2166 | Views in the last 30 days: 3
Related Articles

Versioning database release and permission scripts

How do you version permission scripts


Changing SQL Server Database Logical Names

SQL Server Databases are made up of physical and logical names. This article goes over the logical n...


SQL Database Migration: Lower to Higher Version

Database Migration - Lower version of Microsoft SQL Server to Higher version of SQL Server, with com...


Ignoring Database Version Control

Steve Jones thinks version control is important, even for databases.


Restoring a database from higher version to lower version SQL server

Restoring a database from higher version to lower version SQL server How to downgrade a database fr...

sql server 2005