views:

115

answers:

3

The problem: we have one application that has a portion which is used by a very small subset of the total users, and that part of the application is running off of a separate database as well. In a perfect world, the schemas of the two databases would be synced up, but such is not the case. Some migrations have been run on the smaller database, most haven't; and furthermore, there is nothing such as revision number to be able to easily identify which have and which haven't. We would like to solve this quandary for future projects. During a discussion we've come up with the following possible plan of action, and I am wondering if anyone knows of any project which has already solved this problem:

What we would like to do is create an empty database from the schema of the large fully-migrated database, and then move all of the data from the smaller non-migrated database into that empty one. If it makes things easier, it can probably be assumed for the sake of this problem specifically that no migrations have ever removed anything, only added.

Else, if there are other known solutions, I'd like to hear them as well.

+6  A: 

You could use a schema comparison tool like Red-Gate's SQL Compare. You can synchronize the changes and not lose any data. I wrote about this and many alternative tools ranging widely in price here:

http://www.onetooneinteractive.com/otocorporate-posts/2009/06/01/the-cost-of-reinventing-the-wheel/?showin=otolabs

The nice thing is that most tools have trial versions. So, you can try them our for 14 days (fully functional) and only buy it if it meets your expectations. I can't speak for the other tools, but I've been using RG for years and it is a very capable and reliable tool.

Aaron Bertrand
1) Excellent Article, I sent it to the rest of my team as well.2) This is one of those projects where, without being VERY persuasive, there was 0 software purchase budget. However, the Open DBDiff that was linked to seems like it will be an excellent tool for what I need to do.Many thanks!
Zind
A: 

Red-Gate's SQL Compare as Aaron Bertrand mentions in his answer is a very good option. However, if you are not permitted to purchase something, an option is to try something like:

1) For each database, script out all the tables, constraints, indexes, views, procedures, etc.

2) run a DIFF, and go through all the differences and make sure that the small DB can accept them. If not implement any changes (including data) necessary onto the small DB so it can accept the changes.

3) create a new empty database from the schema of the large DB

4) import the data from the small DB into the nee DB.

KM
A: 

You could also reverse engineer your database into Visual Studio as a database project. Visual Studio Team Suite Database Edition GDR R2 (I know long name) has the capability to do a schema comparison and data comparison, but the beauty of this approach is that you get all of your database into a nice database project where you can manage change and integrate with source control. This would allow you to build from a common source and deploy consistent changes.

Doug Stalter