0
0
dbtdata~5 mins

Unique key for merge behavior in dbt - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a unique key in the context of merge behavior in dbt?
A unique key is a column or set of columns that uniquely identify each row in a table. It helps dbt know which rows to update or insert during a merge operation.
Click to reveal answer
beginner
Why is specifying a unique key important for merge operations in dbt?
Specifying a unique key ensures that dbt can correctly match existing rows to update them and avoid duplicate rows when merging new data.
Click to reveal answer
intermediate
What happens if you do not specify a unique key in a dbt merge operation?
Without a unique key, dbt cannot reliably match rows, which may cause errors or duplicate data during the merge.
Click to reveal answer
intermediate
How do you define a unique key in a dbt model for merge behavior?
You define the unique key in the model's config block using the unique_key parameter, listing the column(s) that uniquely identify rows.
Click to reveal answer
beginner
Give an example of a unique key configuration in a dbt model.
Example: {{ config(materialized='incremental', unique_key='id') }} means the 'id' column uniquely identifies each row for merge.
Click to reveal answer
What does the unique key do in a dbt merge operation?
ADeletes duplicate rows automatically
BSorts the data alphabetically
CIdentifies rows to update or insert
DCreates new columns in the table
What might happen if you omit the unique key in a dbt incremental model?
AThe model runs faster
BNothing changes
CThe data is automatically cleaned
DDuplicate rows or errors may occur
How do you specify a unique key in a dbt model?
AIn the SQL SELECT statement
BIn the model's config block with 'unique_key'
CBy naming the model file uniquely
DBy creating an index in the database
Which of these is a good choice for a unique key?
AA column that uniquely identifies each row
BA column with many repeated values
CA column with null values
DA column with random text
In dbt, what type of model typically uses a unique key for merge behavior?
AIncremental models
BSnapshot models
CEphemeral models
DView models
Explain why a unique key is necessary for merge behavior in dbt incremental models.
Think about how dbt knows which rows to change or add.
You got /4 concepts.
    Describe how to set a unique key in a dbt model and what happens if it is missing.
    Focus on the config syntax and consequences.
    You got /3 concepts.