dbt Fundamentals
Back to Advanced dbt

Snapshots — dbt's SCD Type 2

dbt's built-in tool for tracking dimension changes over time. FIND_VIDEO: search 'dbt snapshots SCD type 2' — recommended channel: dbt Labs. Aim for 11 min or under.

12 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Source Data Setup — Set up a mock orders source table in Snowflake with business keys and timestamp columns.
  2. Snapshot Block Configuration — Define a snapshot file in dbt with target schema, unique key, and timestamp strategy.
  3. Initial Snapshot Execution — Run dbt snapshot to materialize the target table and review dbt metadata columns.
  4. Source Data Mutation — Update source rows with new status values and advanced timestamps in Snowflake.
  5. Change Detection Mechanics — Inspect dbt execution logs and internal SQL join logic evaluating row checksums.
  6. SCD Type 2 Output Verification — Query the snapshot table to verify closed validity windows on historical rows.
PDF notes

Frequently asked questions

What happens to dbt_valid_to when an existing row is updated in the source?

dbt sets the historical row's `dbt_valid_to` to the new record's `updated_at` value and inserts the updated record with `dbt_valid_to = NULL`.

Why does dbt calculate MD5 checksums during snapshot runs?

MD5 checksums allow dbt to compare the combined state of business keys and timestamps across tables quickly using a single hash value.

How do downstream dbt models reference a snapshot table?

Downstream models reference snapshots using the standard `ref()` Jinja function, exactly like referencing regular dbt models.

Where in the project repository should snapshot files be placed?

Snapshot files ending in `.sql` are stored by convention in the `snapshots/` directory of your dbt project.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.