Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Comparing column data in 2 tables with the same schema containing 1.5 billion records Expand / Collapse
Author
Message
Posted Sunday, April 14, 2013 5:07 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 9:35 PM
Points: 402, Visits: 936
I have had the task of recreating a table in our data warehouse which contains 1.5 billions rows to make use of partioning on the clustered index by date. To keep the tables in sync over the past few weeks I have had to run import jobs on both tables.

Before moving across to the new partitioned table (by renaming it to bring it into production) I need to ensure that the EffectiveEndDate column in both tables is identical for every row (which has a PK).

So my question is how best is it to compare 2 tables with 1.5 billion records to ensure the data in both is the same?

At this stage 3rd party tools are not an option and I am using SQL Server 2012 SP1 Enterprise Edition.

Any help greatly appreciated!!
Post #1442148
Posted Monday, April 15, 2013 5:41 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:11 PM
Points: 6,466, Visits: 13,921
are you saying you just want to check the data is identical for each row across all columns?


-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs"
Post #1442267
Posted Monday, April 15, 2013 10:46 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 9:35 PM
Points: 402, Visits: 936
Hi Perry,

Thanks for getting back - in reality I just need to check that data in a single column is the same for each matching PK in the 2 tables.

So each table as an ID and an EffectiveEndDate column - each table will have the same number of rows - approx 1.5 billions rows. They should be a copy of each other but I need to ensure for each row has the same value for EffectiveEndDate in both tables,

Thanks again for your reply,

JK
Post #1442574
Posted Tuesday, April 16, 2013 1:36 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:55 AM
Points: 6,782, Visits: 13,988
JayK (4/14/2013)
I have had the task of recreating a table in our data warehouse which contains 1.5 billions rows to make use of partioning on the clustered index by date. To keep the tables in sync over the past few weeks I have had to run import jobs on both tables.

Before moving across to the new partitioned table (by renaming it to bring it into production) I need to ensure that the EffectiveEndDate column in both tables is identical for every row (which has a PK).

So my question is how best is it to compare 2 tables with 1.5 billion records to ensure the data in both is the same?

At this stage 3rd party tools are not an option and I am using SQL Server 2012 SP1 Enterprise Edition.

Any help greatly appreciated!!


Start simple. Create a unique index on each table with columns ID and EffectiveEndDate.
Then run
SELECT 
t2.ID, t1.ID,
t2.EffectiveEndDate, t1.EffectiveEndDate
FROM Table1 t1
INNER JOIN Table2 t2
ON t2.ID = t1.ID
AND t2.EffectiveEndDate <> t1.EffectiveEndDate



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1442625
Posted Tuesday, April 16, 2013 1:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:11 PM
Points: 6,466, Visits: 13,921
JayK (4/15/2013)
Hi Perry,

Thanks for getting back - in reality I just need to check that data in a single column is the same for each matching PK in the 2 tables.

So each table as an ID and an EffectiveEndDate column - each table will have the same number of rows - approx 1.5 billions rows. They should be a copy of each other but I need to ensure for each row has the same value for EffectiveEndDate in both tables,

Thanks again for your reply,

JK

use a select query on the columns required from each of the tables and apply the except operator, any differences in the column data will be returned, like so

select somecolumn, anothercolumn from thetablea
except
select somecolumn, anothercolumn from thetableb



-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs"
Post #1442634
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse