Visual Studio 2012 Schema Comparison
Join the DZone community and get the full member experience.Join For Free
having recently been playing with the newly released visual studio 2012, one of the really nice features that i’ve seen is the database schema comparison functionality.
if you’d like to follow along with this, you’ll need the contosobi database, which is available here .
this can be seen by launching vs2012, choosing new project, and selecting the sql server database project. don’t forget to give the project a name, i called mine dbschemacomparison.
when the solution has been created, you’ll be presented with the solution explorer.
in here, you’ll want to right-click on the project name, and choose import > database. in here, you’ll need to create a new connection to your database. also, if you are wanting to track everything, you need to check the permissions and database settings tick boxes. then click start.
while the process is running, you’ll be presented with a dialog box showing the progress. when it’s completed, click finish.
now, when you look in the solution explorer, you’ll see a set of sql scripts that have been created to match the structure in the database.
my next step was to connect to the database using sql server management studio, and alter one of the tables. i decided to add an index to the dimaccount table. the index was called ix_date, and i added the loaddate field from the dimaccount table to it.
the final step in this process is to go back into visual studio, right click on the project and choose schema compare. when this window opens, you have two drop down boxes. the left contains the project that you have in vs2012; the right will need to be populated with a database for comparison.
when you’ve populated the database on the right, click the compare button. the schemas from the two projects are loaded and compared. the results are then displayed on the screen. as can be seen below, it’s pretty obvious what the differences between the environments are.
if you then want to sync the environments, you need to remember that you need to move the changes from source (left) to target (right). if you want to remove them from the right (database), then you can click update (or the script button next to it, to generate a script). alternatively, if you want to update your project, you can click the ‘switch’ button between the two projects and rerun the compare.
a really nice feature, i think you’ll agree.
Opinions expressed by DZone contributors are their own.