Wednesday, August 15, 2007

SQL2005 Table comparison tool

TableDiff.exe is a table comparison tool that comes with the sql server.

It's installed on the server in the:
"C:\Program Files\Microsoft SQL Server\90\COM\TableDiff.exe"

Example use:

This compares 2 tables in the same database on the same server and creates a new table called DiffsTable that holds the differences:

CODE
"C:\Program Files\Microsoft SQL Server\90\COM\tablediff.exe" -sourceserver MyServer1
                                                             -sourcedatabase MyDatabase1
                                                             -sourcetable MyTable1
                                                             -destinationserver MyServer1  
                                                             -destinationdatabase MyDatabase1
                                                             -destinationtable MyTable2
                                                             -et DiffsTable


This compares 2 tables in the same database on the same server and creates a new table called DiffsTable that holds the differences and creates a T-SQL script file at d:\MyTable1_MyTable2_diff.sql

that holds the UPDATE/INSERT/DELETE statements to synchronize the 2 tables:
CODE
"C:\Program Files\Microsoft SQL Server\90\COM\tablediff.exe" -sourceserver MyServer1  
                                                             -sourcedatabase MyDatabase1
                                                             -sourcetable MyTable1
                                                             -destinationserver MyServer1  
                                                             -destinationdatabase MyDatabase1
                                                             -destinationtable MyTable2
                                                             -et DiffsTable
                                                             -f d:\MyTable1_MyTable2_diff.sql


You can also get simple GUI for this tool:

0 comments: