0
0
dbtdata~20 mins

Slowly changing dimensions (SCD Type 2) in dbt - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SCD Type 2 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
AThe count of active records equals the total rows in target_table before merge.
BThe count of active records equals the number of unique customers in source_table.
CThe count of active records equals zero after the merge.
DThe count of active records equals the number of rows in source_table plus target_table.
Attempts:
2 left
💡 Hint
Think about how SCD Type 2 keeps one active record per customer.
data_output
intermediate
2: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?
A3 records
B4 records
C6 records
D5 records
Attempts:
2 left
💡 Hint
Each changed customer adds a new record, unchanged stays the same.
🔧 Debug
advanced
2: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;
ARuntime error due to ambiguous column reference in join.
BSyntax error due to missing alias in join.
CNo error, query runs and returns changed customers.
DEmpty result because join condition misses is_current filter on source.
Attempts:
2 left
💡 Hint
Check join conditions and filters carefully.
🚀 Application
advanced
2: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?
AUse incremental strategy with 'merge' and define unique key on customer_id and is_current flag.
BUse full-refresh strategy to reload entire table every run.
CUse incremental strategy with 'insert_overwrite' partitioned by customer_id.
DUse ephemeral materialization to avoid storing data.
Attempts:
2 left
💡 Hint
SCD Type 2 needs to update existing records and insert new ones.
🧠 Conceptual
expert
2: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.
AIt preserves full history of changes by keeping multiple records per entity with time validity.
BIt overwrites old data to keep only the latest snapshot for simplicity.
CIt compresses data by removing duplicates and keeping one record per entity.
DIt stores only the changes as separate delta tables for faster queries.
Attempts:
2 left
💡 Hint
Think about how historical changes are tracked over time.