Search code examples
sql-servercomparisondata-synchronization

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??


Solution

  • 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