r/SQLServer • u/ManufacturerSalty148 • Dec 31 '25
Discussion Best tool or way to compare two Database data
Hi Lots of time I am getting requests to compare data between two Database like for instance one time data analysis told me that he want to see if the data in replica Database match the data in primary Database, i know that's stupid question since both Database are in always on synchronization but it was difficult proving it to him , I search online for a tool to compare Database data majority are paid, there is way with vs code but I found it be too complicated, can anyone share his tool or a way to compare two Database
15
u/radtravis Dec 31 '25
Try this free tool built by SQL Ninjas at Microsoft. It compares not just SQL to SQL but also SQL to other DB types. https://www.microsoft.com/en-us/download/details.aspx?id=103016
3
u/alinroc 4 Jan 01 '26
You're wanting to check that the data is identical between two replicas of a database in an Availability Group?
I'd just respond with "sometimes you have to trust that the software you're paying tens of thousands of dollars for works properly. If the data wasn't identical, Microsoft would have a massive problem on their hands, Azure SQL DB wouldn't work properly/wouldn't be trustworthy, and no one would be using this product."
And if that's not good enough, go with /u/sqlbek's solution.
3
u/Informal_Pace9237 Dec 31 '25
Are the databases accessible to each other?
Can you run a query on one of them or a third server connecting both databases?
15
u/beccalou81 Dec 31 '25
Visual Studio. Go to Tools > SQL Server > New Data Comparison. Follow the wizard to connect to both databases, select which objects you want to compare. It can also script an insert/update/delete statement to bring the database up-to-date with the other.
16
u/pubbing Dec 31 '25
Redgate has a tool called SQL data compare that does this. It isn't free though.
8
u/SQLBek 1 Dec 31 '25
Give him backups of the two databases and tell him to do it himself and stop wasting your time. :-p
1
u/GreatMyUsernamesFree Jan 02 '26
Careful. Don't get caught in a fool's errand. If he can't provide evidence of the databases being out of sync, there's no amount of evidence that can prove to him the databases ARE in sync. It sounds like they doesn't understand the technology very well.
3
u/Itsnotvd Dec 31 '25
"Lots of time I am getting requests to compare data between two Database"
I am the primary DBA where I work and when I get the same request over and over and expect more of the same, I would prefer to buy some DB data comparison tool.
I could can spend some time and figure out some script process. Issue for me is that the secondary DBA's aren't good enough to handle this and thus any script process I have to support eats up time I need to spend elsewhere. There's other reasons too that I'd rather not mention.
The cost of the software is relatively low. It's not too difficult for me to convince management of the advantage of buying something inexpensive to make a recurring task simpler and efficient for the DBA staff and customers.
A good SQL toolset can go a long way in helping you do your daily work. Lots of them out there to choose from. I am using XSQL software schema and data comparison tools. This also simplifies ad hoc data refreshes in non-prod environments.
3
u/da_chicken Dec 31 '25
The quick and dirty way is to use
SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*)) FROM [Table]for each table. You can even dump each table'sCHECKSUM_AGG()into a temp table, thenCHECKSUM_AGG()that table to get an aggregated checksum for the whole database.There are limitations to that. The
BINARY_CHECKSUM()(andCHECKSUM()) functions skip some data types (xml,ntext/text, andimage) unless you convert them tonvarchar(max)/varchar(max)orvarbinary(max).Also, the
BINARY_CHECKSUM()(andCHECKSUM()) functions are not particularly resistant to hash collisions. Neither is theCHECKSUM_AGG()function. So, you can't guarantee that two tables that match the checksum are identical, but you can say that two tables that DON'T match checksums are going to be different.You can switch to
HASHBYTES()with SHA-256 or SHA-512 and then concatenating all the fields in the row into a big text blob of input. You can usually write a query that runs againstINFORMATION_SCHEMA.COLUMNSorsys.columns. But there isn't an equivalent ofCHECKSUM_AGG()(which doesn't care about order) which immediately makes it much more of a PITA.2
u/dgillz Jan 01 '26
SQL Delta. I've been using it for years. Besides data comparisons it can compare table structures, compare schemas, and create a sync between the 2 databases if desired.
And you can purchase it outright rather than having a never-ending subscription.
1
u/paultherobert Dec 31 '25
it depends a bit on what's required too. If this is business data and your analyst who is familiar with it, you might be able to build simple comparison points. You probably don't need to compare every column and row in order to prove they are practically equivalent. For instance, if you have sales data, you can confirm that both systems have the same number of sales orders in a given time period, and you could confirm the sales totals tie out. Again, depends on what is truly required.
1
u/watchoutfor2nd Dec 31 '25
There is a data compare feature built into Visual Studio. You may want to consider the database size before you do this. I've done it on DBs as large as 60gb. It just requires some patience.
1
u/mk32 Dec 31 '25
If you're comfortable with Python, check reladiff. But the support for SQL Server is still not out.
1
u/alexwh68 Dec 31 '25
Depends on the level of comparison, most robust but unlikely to be useful for the db is checksum the whole database with something like a md5 checksum this is a bit level comparison of the whole file.
Second level is script out both db’s schema to a file and check the md5 checksums of the two output scripts this makes sure that structurally the databases contain the same tables and fields in the tables.
Third level is to export the actual tables to csv, then compare those for both db’s.
If the schemas for both db’s is the same you can use .net with entity framework to open each table as a list<> then compare those list<>’s
I had to write tools to make sure the developer environment was in sync with production for a number of large databases for one company I worked for using the above as basic ideas
1
u/Kuldera Jan 01 '26
https://www.capitalone.com/tech/open-source/datacompy-open-source-dataframe-comparisons/
This is my favorite python package for these kinds of tasks.
-1
u/JasonLokiSmith Dec 31 '25
Export the 2 tables from the different databases into plain text formats like CSV and download devart code compare or winmerge and compare the tables file by file