DBT DBT Snapshots & Incremental Models 1 — Questions and Answers
Question 1: What is the primary purpose of a dbt snapshot?
- To cache query results for performance
- To capture and track slowly changing dimension (SCD) history in a source table (Correct answer)
- To take a database backup before a run
- To freeze a model's schema for documentation
Correct answer: To capture and track slowly changing dimension (SCD) history in a source table
dbt snapshots implement Type 2 SCD logic, appending new rows when source data changes so you can query historical states.
Question 2: Which directory stores dbt snapshot files by default?
- models/snapshots/
- snapshots/ (Correct answer)
- data/snapshots/
- seeds/
Correct answer: snapshots/
Snapshot `.sql` files are placed in the top-level `snapshots/` directory of a dbt project.
Question 3: What command runs all dbt snapshots?
- dbt run --snapshots
- dbt snapshot (Correct answer)
- dbt materialize --type snapshot
- dbt scd
Correct answer: dbt snapshot
`dbt snapshot` executes all snapshot files, applying the configured strategy to detect and record changes.
Question 4: Which snapshot strategy compares a hash of all specified columns to detect row changes?
- timestamp
- check (Correct answer)
- merge
- diff
Correct answer: check
The `check` strategy hashes the values of listed columns and records a new snapshot row when the hash changes, useful when no reliable updated_at column exists.
Question 5: Which snapshot strategy relies on an `updated_at` timestamp column to detect changes?
- check
- hash
- timestamp (Correct answer)
- merge
Correct answer: timestamp
The `timestamp` strategy compares the `updated_at` value between runs and creates new snapshot rows for records with a newer timestamp.
Question 6: What column does dbt automatically add to a snapshot table to mark the time a record became current?
- dbt_updated_at
- dbt_valid_from (Correct answer)
- dbt_created_at
- snapshot_start
Correct answer: dbt_valid_from
`dbt_valid_from` is automatically populated with the timestamp when a snapshot row became the current version of the record.
What is the primary purpose of a dbt snapshot?