Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Source only and mismatch data with tablediff utility

I'm using tablediff utility to transfert data from serval databases sources to a destination database and I get a result having all the differences between the source and destination databases with something like this

Dest. Only  N'1027' N'799'  N'91443'    N'1'    
Mismatch    N'103A' N'799'  N'13010'    N'1'    DATE_CURRENT DATE_OPERATION MATRICULE_UTILISATEUR QTE QTE_FINAL QTE_INIT QTE_OPERATION REFERENCE_DOCUMENT TYPE_DOCUMENT 
Src. Only   N'103A' N'310'  N'30129'    N'1'    

so the generated sql file contain delete the Dest. Only rows, update the Mismatch rows and insert the Src. Only rows

My question is: Is there any way using tablediff to get the result of only Mismatch and Src. Only rows??

like image 336
Billydan Avatar asked Jun 16 '16 13:06

Billydan


People also ask

How do I use the tablediff utility?

The tablediff utility is used to compare the data in two tables for non-convergence, and is particularly useful for troubleshooting non-convergence in a replication topology. This utility can be used from the command prompt or in a batch file to perform the following tasks:

What is the difference between source and destination tables in tablediff?

-destinationtable: The table in the destination database that will be compared to the source table. The tablediff utility compares the data in the source table to the table in the destination table.

What is tablediff in SQL Server?

Among the many command-line utilities provided with SQL Server, one of particular note is tablediff, a handy tool that lets you compare the data in two tables in order to identify any discrepancies.

How do I restrict data type mappings in tablediff?

By default, the tablediff utility supports the following data type mappings between source and destination columns. Use the -strict option to disallow these mappings and perform a strict validation. The source table in the comparison must contain at least one primary key, identity, or ROWGUID column.


1 Answers

In the end of your tablediff tool command add the following

-dt -et DiffResults

It will drop an existing table with name DiffResults and create a new one in the destination server and database. Then you can query the DiffResults table to get the desired rows. In my test I run the following

SELECT * FROM DiffResults
WHERE MSdifftool_ErrorDescription in ('Mismatch','Src. Only')

or

SELECT * FROM DiffResults
WHERE MSdifftool_ErrorCode in (0,2) -- 0 is for 'Mismatch';  1 is for 'Dest. Only' and 2 is for 'Src. Only'

Some more details can be found here - https://technet.microsoft.com/en-us/library/ms162843.aspx

like image 54
Igor Micev Avatar answered Oct 22 '22 04:10

Igor Micev