How to compare data between two table in different databases using Sql Server 2008?

前端 未结 9 2264
一生所求
一生所求 2020-12-13 17:41

I have two database\'s, named DB1 and DB2 in Sql server 2008. These two database\'s have the same tables and same table data also. However, I want to check if there are an

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 17:57

    I'v done things like this using the Checksum(*) function

    In essance it creates a row level checksum on all the columns data, you could then compare the checksum of each row for each table to each other, use a left join, to find rows that are different.

    Hope that made sense...

    Better with an example....

    select *
    from 
    ( select checksum(*) as chk, userid as k from UserAccounts) as t1
    left join 
    ( select checksum(*) as chk, userid as k from UserAccounts) as t2 on t1.k = t2.k
    where t1.chk <> t2.chk 
    

提交回复
热议问题