Skip to main content

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.

                                  Figure: SQL Server Data Tools can be handier than any of these tools

Visual Studio SQL Data Tools

Tool -> SQL  Server -> New Data Compare

SQL Server Data Compare

Then we have to select source and destination. Then check the options you want to compare

SQL Data Compare

Then select the objects you want to compare (table or view)
After comparison, you can output something like this - 

SQL different records


  • Different Records - Records that exist in both source and destination. These will be updated in destination
  • Only In Source - Data in Source DB, NOT in Destination, these data need to be added
  • Only in Destination - Data in Destination DB, NOT in source, these data need to be deleted
  • Identical Records - Data Identical in both source and destination.

Click on generate scripts, you will get a script for this data migration :D 

data migration with script

You can run it in Visual Studio Or SSMS

SSMS update data SQL Data Tools

Run this script on destination to make it the same as the source

This script performs its actions in the following order:

  • Disable foreign-key constraints.
  •  Perform DELETE commands. 
  • Perform UPDATE commands.
  • Perform INSERT commands.
  • Re-enable foreign-key constraints.

Please back up your target database before running this script. Because you know, murphy's law states that, "If anything can go wrong, it will" 

Comments

  1. Excellent Post. The post is very useful to me as it contains some unique information about SQL which is really amazing. Thanks for posting it. Looking for Data Replication Software Online then visit on Repstance.

    ReplyDelete

Post a Comment

Most Loved Posts

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>();

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

6 Letters for SQL Disaster Emergencies : RPO and RTO