Comparison for 75 tables in two different SQL Server databases

dang tran 1 Reputation point
2021-12-22T17:30:36.12+00:00

I'm trying to do a column by column, row by row comparison for 75 tables in two different databases. The tables contain up to 165 million records.

I need to determine if there are any missing records, and we need to identify any columns that contain different values. Potential problems include decimal errors.

Thanks for any assistance or advice.

SQL Server | Other
{count} votes

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2021-12-22T22:44:06.447+00:00

    Duplicate thread with SQL Server Central: https://www.sqlservercentral.com/forums/topic/comparison-for-75-tables-in-two-different-sql-server-databases#post-3966337

    For convenience, I'm copying the answer I posted on SSC:

    I believe there is a Data Compare option in Visual Studio if you have SSDT installed.

    Else you can run queries like this:

    SELECT *
    FROM   dbA.dbo.tbl A
    FULL JOIN dbB.dbo.tbl B ON A.keycol = B.keycol
    WHERE NOT EXISTS (SELECT A.* INTERSECT SELECT B.*)
    

    This assumes that you want to compare each and every column. If you want to exempt one or more columns you need replace A.* and B.* with explicit column lists.

    I suggest that you try the pattern above on one table before you proceed further.

    1 person found this answer helpful.
    0 comments No comments

  2. AmeliaGu-MSFT 14,011 Reputation points Microsoft External Staff
    2021-12-23T02:36:30.49+00:00

    Hi dangtran-6885,
    Agree with others.
    You can go to SSDT Tools menu ->SQL Server-> new data comparison to compare records between multiple tables.

    159905-image.png

    After selecting connection to Source Database and Target Database in the Choose Source and Target Databases dialog box, you can select tables to compare.

    159913-image.png

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  3. Tom Phillips 17,781 Reputation points
    2021-12-22T17:54:10.81+00:00
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.