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??
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:
-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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With