Profile

Sunday, 29 May 2011

SQL: compare tables 1: Row Count

Say you have two databases: one is a production DB-PRO and the other is a data warehouse DB-DWH. You made a copy of table dbo.PART from production to data warehouse. Now you want to make sure both tables are the same.

There are two factors to compare tables: Row count and Distinct data value. If table A is EXACTLY like table B, then the number of rows of A should equal B, and there should be no distinct data in either table.

Lets do the row count first:

             SELECT COUNT  (*) FROM DB-PRO.dbo.[PART]
             SELECT COUNT (*) FROM DB-DWH.dbo.[PART]

After you run this on SQL, it should give you a row count on both tables: