Skip to main content

SQL Schema Compare with Visual Studio (A complete Guide)

Introduction

When you're working on your Dev Database, an urgent issue comes along, and you instantly solve it by changing Scheme in the Staging Database or Production Database :3, few more these type of patching and you're completely out of sync!

A lot of paid alternatives are there like SQL Data Compare by RedGate, but my first choice is Visual Studio's SQL Data Tools. In the following article, I tried to image-describe the steps for SQL Data Tool.

Like I said before, there are lots of handly DBAtools out there to compare Schema between two DB Sources. I would like to discuss how you can compare two SQL Server DB with Visual Studio.

Make sure you have SQL Server Data tools checked while installing Visual Studio.

SQL Server Data Tools

   Comapre Scema

Open VS and select SQL Schema Compare under tools > SQL Server> New Scheme Compare

Then, Select Source and Destination Database Source with Catalog name


After Selecting the Source and Database, click on "Compare"

Then the comparison begins and you wait for it to complete. The bigger the DB with respect to Schema, the more time it takes.


After the comparison is complete, you can see the changed items and added items.

Click on the items you want to move to Source to Destination :D 

Click Shift + Alt + G to generate Scripts to update Schema from Source to Destination

The generated scripts will be open in a separate window


You can Run from Visual Studio Or copy-paste the Script and Run in your destination db SSMS.

If you run from SSMS, make sure SQLCMD in enabled.


Conclusion

In today's article, we have seen how we can easily compare schema across different server hosted same Database. Visual Studio's build in SQL Schema comparison is a free tool for this compared to other paid alternatives.

Comments

Most Loved Posts

Intelligent Query Processing in SQL Server 2019 Big Data

SQL Server 2019: Intelligent Query Processing SQL Server 2019 ships with some brand-new features. Many of these features are targeted for Big Data Solutions. No wonder in that, since the world is moving faster towards Big Data and it is absolutely necessary to cope up with that. Today we will discuss one such feature called Approximate Query Processing. Approximate Query Processing SQL Server ships with Intelligent Query Processing out of the box with SQL Server 2019 installation. Approximate Query processing is a part of Intelligent Query Processing. Things we will be covering in this article – Understand the need for Approximation with Case Study Case Study 1: Railway Case Study 2: e-commerce How to use Approximate Query Processing Demo Code for Comparing Performance Results Limitations When to avoid Approximate Query Processing Understand the need for Approximate Query Processing Before using any technological feature, we must understand why we should use it? Should we jus

How to generate C# Class from SQL Server Table

C# Class from SQL Database Table There are multiple ways you can generate a C# class from your Database Table. We will be covering the following topics in today’s article. Generate Class with foreign key relation Generate Class with only entities Generate Class with foreign key relations For this we can simply use Entity Frameworks EDMX update feature which will generate our C# class from Database Tables. The output from EDMX will contain foreign key relations which we can see from the virtual interfaces like this -  public partial class AssetItem { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] public AssetItem() { this .AssetItemDepreciations = new HashSet<AssetItemDepreciation>(); this .AssetTaxMappings = new HashSet<AssetTaxMapping>(); this .AssetVatMappings = new HashSet<AssetVatMapping>();

6 Letters for SQL Disaster Emergencies : RPO and RTO

 

SQL Data Tools - Compare Data

Compare Data between two tables SQL Server Database with the same schema architecture can differ in different environments like Dev, Staging, and Production, especially in configuration tables. Let's see how we can easily sync the data in two different tables.