Intermediate TrackBack
Intermediate
🚀
SCD Type 2: Historical Tracking
The gold standard for complete history preservation.
Section 1 of 4: Type 2 Concept0%
Type 2 Concept
Study Material
SCD Type 2: Create a New Row
When data changes, keep the old row and create a new one. This preserves complete history - the most powerful SCD type.
How It Works:
Customer Sarah moves from NY to CA on March 15, 2024:
Before (1 row):
| customer_key | customer_id | state | effective_date | expiration_date | is_current |
|---|---|---|---|---|---|
| 1001 | CUST001 | NY | 2023-01-01 | 9999-12-31 | TRUE |
After (2 rows):
| customer_key | customer_id | state | effective_date | expiration_date | is_current |
|---|---|---|---|---|---|
| 1001 | CUST001 | NY | 2023-01-01 | 2024-03-14 | FALSE |
| 2547 | CUST001 | CA | 2024-03-15 | 9999-12-31 | TRUE |
Key Components:
1. Surrogate Key (customer_key)
- Unique per VERSION, not per customer
- Customer CUST001 now has TWO surrogate keys
- Fact tables link to specific versions
2. Natural Key (customer_id)
- Same across all versions
- Identifies the business entity
3. Effective Date (effective_date)
- When this version became active
- Start of validity period
4. Expiration Date (expiration_date)
- When this version ended
- '9999-12-31' = still current (convention)
- Or use NULL for current
5. Current Flag (is_current)
- Easy way to find current record
- Only ONE row per customer has TRUE
Why This Works:
- Fact tables link to customer_key (surrogate)
- Sarah's Q1 orders link to key 1001 (NY version)
- Sarah's Q2 orders link to key 2547 (CA version)
- Historical accuracy preserved automatically!