A dbt model for SCD Type 2 is not updating the end_date correctly. Which fix is most appropriate?
medium📝 Debug Q7 of 15
dbt - Advanced Patterns
A dbt model for SCD Type 2 is not updating the end_date correctly. Which fix is most appropriate?
ASet end_date to NULL for all records
BAdd a step to update end_date of old records before inserting new ones
CDelete all records before each run
DRemove the effective_date column from the model
Step-by-Step Solution
Solution:
Step 1: Identify correct SCD Type 2 update process and evaluate fixes
Old records must have their end_date set to expire them before new versions insert. Add a step to update end_date of old records before inserting new ones adds this necessary step; others break history or data integrity.
Final Answer:
Add a step to update end_date of old records before inserting new ones -> Option B
Quick Check:
Expire old records before new insert [OK]
Quick Trick:Expire old records by updating end_date first [OK]
Common Mistakes:
MISTAKES
Deleting data instead of updating
Removing effective_date
Setting end_date NULL incorrectly
Master "Advanced Patterns" in dbt
9 interactive learning modes - each teaches the same concept differently