Use Tablediff to compare all tables

I recently discovered a tablediff utility for SQL Server 2005.

I have two instances of the same database on different servers.

Is it possible to compare all tables using tablediff without having to replicate the same command when changing the table name?

For example, compare table1 with server1 with table 1 on server2, and then compare table2 with server1 with table2 on server2 until all tables are compared.

+5
source share
3 answers

, -sourceserver tablediff -destinationserver . sys.Tables , .

Edited

, t-sql, tablediff

, . , . , SSIS, .

SET QUOTED_IDENTIFIER ON 

DECLARE @TableNames as table (
    id int identity(1,1),
    tableName varchar(100))

DECLARE @sTableDiff nvarchar(1000)
DECLARE @tableName varchar(100)
DECLARE @counter int
DECLARE @maxCount int

INSERT INTo @TableNames 
SELECT name 
FROM sysobjects WHERE type = 'U'

SET @counter = 1

SELECT @maxCount = COUNT(name) 
FROM sysobjects WHERE type = 'U'

WHILE @counter < @maxCount
    Begin
        SELECT @tableName = tableName 
        FROM @TableNames 
        WHERE id = @counter

        SET @sTableDiff= ' "C:\Program Files\Microsoft SQL Server\90\COM\tablediff" -sourceserver Server1 
            -sourceuser sa -sourcepassword password -sourcedatabase YourDatabase -sourcetable ' + @tableName + ' 
            -destinationserver Server2 -destinationuser sa -destinationpassword password -destinationdatabase 
            YourDatabase -destinationtable ' + @tableName + '  -f c:\Diff'      

        EXEC XP_CMDSHELL @sTableDiff

        Set @counter = @counter + 1
    End
+7

Can you use this option to run sql statements in a script file and compare? Maybe I'm wrong.

-bf number_of_statements

0
source

All Articles