Challenge - 5 Problems
SCD Type 2 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this SCD Type 2 merge logic?
Given the following dbt SQL snippet for SCD Type 2, what will be the count of active records after running this merge?
dbt
merge into target_table as tgt using source_table as src on tgt.customer_id = src.customer_id and tgt.is_current = true when matched and (tgt.address != src.address) then update set tgt.is_current = false, tgt.end_date = current_date when not matched then insert (customer_id, address, start_date, end_date, is_current) values (src.customer_id, src.address, current_date, null, true);
Attempts:
2 left
💡 Hint
Think about how SCD Type 2 keeps one active record per customer.
✗ Incorrect
SCD Type 2 logic marks old records as inactive and inserts new active records for changed data. So, after merge, active records correspond to unique customers in source.
❓ data_output
intermediate2:00remaining
How many records will be in the target after this SCD Type 2 update?
Assume target_table has 3 customers with 1 record each (all active). source_table has 2 customers with changed addresses and 1 unchanged. After running the SCD Type 2 merge, how many total records will target_table have?
Attempts:
2 left
💡 Hint
Each changed customer adds a new record, unchanged stays the same.
✗ Incorrect
Two customers changed, so their old records become inactive and new records inserted. One unchanged customer keeps one record. Total = 3 original + 2 new = 5.
🔧 Debug
advanced2:00remaining
Identify the error in this SCD Type 2 dbt model SQL
This dbt model attempts to implement SCD Type 2 but has a bug. What error will occur when running it?
dbt
with source as ( select * from {{ ref('source_table') }} ), updates as ( select src.customer_id, src.address from source src join {{ ref('target_table') }} tgt on src.customer_id = tgt.customer_id where src.address != tgt.address and tgt.is_current = true ) select * from updates;
Attempts:
2 left
💡 Hint
Check join conditions and filters carefully.
✗ Incorrect
The query correctly joins source and target on customer_id and filters for changed addresses where target is current. No syntax or runtime errors occur.
🚀 Application
advanced2:00remaining
Which dbt configuration best supports SCD Type 2 incremental model?
You want to build an incremental dbt model for SCD Type 2. Which configuration option is most appropriate to handle updates and inserts correctly?
Attempts:
2 left
💡 Hint
SCD Type 2 needs to update existing records and insert new ones.
✗ Incorrect
Incremental with merge and unique keys allows updating old records and inserting new ones, which fits SCD Type 2 logic.
🧠 Conceptual
expert2:00remaining
Why is SCD Type 2 important for historical data analysis?
Choose the best explanation for why SCD Type 2 is used in data warehouses.
Attempts:
2 left
💡 Hint
Think about how historical changes are tracked over time.
✗ Incorrect
SCD Type 2 keeps old records with end dates and inserts new records for changes, preserving full history for analysis.