Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of the ref() function in dbt?
The ref() function creates a dependency between dbt models by referencing one model inside another. It helps dbt understand the order to run models and manage dependencies automatically.
Click to reveal answer
beginner
How does ref() help with model dependency management?
ref() tells dbt which models depend on others. This way, dbt runs models in the right order and rebuilds only what is needed when data or logic changes.
Click to reveal answer
intermediate
What happens if you use ref('model_name') inside a model SQL file?
Using ref('model_name') inserts the correct table or view name for that model in the compiled SQL. It also creates a dependency link so dbt knows to build that model first.
Click to reveal answer
intermediate
Can you use ref() to reference models across different dbt projects?
No, ref() only works within the same dbt project. To reference models across projects, you need to use other methods like external tables or sources.
Click to reveal answer
beginner
Why is it better to use ref() instead of hardcoding table names in dbt models?
Using ref() makes your project more flexible and maintainable. If table names or schemas change, dbt updates references automatically. Hardcoding names can cause errors and extra work.
Click to reveal answer
What does the ref() function do in dbt?
ACreates a dependency between models
BRuns SQL queries faster
CDeletes old models
DGenerates documentation
✗ Incorrect
ref() creates dependencies so dbt knows the order to build models.
Which of these is a benefit of using ref() in dbt?
AAutomatically manages model build order
BEncrypts data in models
CImproves network speed
DCreates new database users
✗ Incorrect
ref() helps dbt run models in the correct order based on dependencies.
What happens if you hardcode table names instead of using ref()?
Adbt ignores dependencies
Bdbt runs models faster
CModels automatically update schema
DYour project becomes less flexible and error-prone
✗ Incorrect
Hardcoding table names can cause errors if names or schemas change, unlike ref() which updates automatically.
Can ref() be used to reference models in other dbt projects?
AYes, across any projects
BOnly if projects share the same database
CNo, only within the same project
DOnly for models in the same folder
✗ Incorrect
ref() works only within the same dbt project.
What does ref('model_name') return inside a model SQL file?
AThe database connection string
BThe compiled table or view name for that model
CThe raw SQL code of the model
DThe model's documentation URL
✗ Incorrect
ref() inserts the correct compiled table or view name for the referenced model.
Explain how the ref() function helps dbt manage model dependencies and build order.
Think about how dbt knows which model to build first.
You got /3 concepts.
Describe why using ref() is better than hardcoding table names in dbt models.
Consider what happens if a table name changes in your project.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the ref() function in dbt?
easy
A. To create new database users
B. To write raw SQL queries inside dbt models
C. To link models and define dependencies between them
D. To schedule dbt runs automatically
Solution
Step 1: Understand the role of ref()
The ref() function is used to link one model to another in dbt, so dbt knows the order to run models and their dependencies.
Step 2: Identify what ref() does not do
It does not write raw SQL, create users, or schedule runs. Its main role is linking models.
Final Answer:
To link models and define dependencies between them -> Option C
Quick Check:
ref() links models = A [OK]
Hint: Remember: ref() connects models, not SQL or users [OK]
Common Mistakes:
Thinking ref() writes SQL code
Confusing ref() with scheduling tools
Assuming ref() manages database users
2. Which of the following is the correct syntax to reference a model named customers inside another model using ref()?
easy
A. select * from {{ ref('customers') }}
B. select * from ref('customers')
C. select * from ref(customers)
D. select * from {{ ref(customers) }}
Solution
Step 1: Recall dbt Jinja syntax for ref()
In dbt, ref() must be wrapped in double curly braces and the model name must be a string in quotes.
Step 2: Check each option
select * from {{ ref('customers') }} uses {{ ref('customers') }} which is correct. Options B and C miss the curly braces or quotes. select * from {{ ref(customers) }} misses quotes around the model name.
Final Answer:
select * from {{ ref('customers') }} -> Option A
Quick Check:
Use {{ ref('model_name') }} syntax = A [OK]
Hint: Always use {{ ref('model_name') }} with quotes and braces [OK]
Common Mistakes:
Omitting curly braces {{ }}
Not putting model name in quotes
Using ref() without Jinja syntax
3. Given the following dbt model code, what will be the output SQL after compilation if the orders model exists?
select order_id, customer_id
from {{ ref('orders') }}
medium
A. select order_id, customer_id from orders
B. select order_id, customer_id from {{ ref('orders') }}
C. select order_id, customer_id from dbt.orders
D. select order_id, customer_id from ref('orders')
Solution
Step 1: Understand what ref() compiles to
The ref() function compiles to the actual table name of the referenced model, usually just the model name like 'orders'.
Step 2: Check the compiled SQL output
The compiled SQL replaces {{ ref('orders') }} with orders, so the output is select order_id, customer_id from orders.
Final Answer:
select order_id, customer_id from orders -> Option A
Quick Check:
ref('orders') compiles to orders = C [OK]
Hint: ref() compiles to the model's table name without braces [OK]
Common Mistakes:
Leaving ref() uncompiled in SQL
Adding extra schema prefix without config
Using ref() as a string literal
4. You wrote this dbt model code:
select * from ref('sales')
When you run dbt, you get an error. What is the problem?
medium
A. Quotes around 'sales' should be removed
B. Model name 'sales' does not exist
C. ref() cannot be used inside select statements
D. Missing double curly braces around ref()
Solution
Step 1: Check the syntax of ref() usage
In dbt, ref() must be wrapped in double curly braces to be interpreted as Jinja code.
Step 2: Identify the error cause
The code uses ref('sales') without {{ }}, so dbt treats it as plain text, causing an error.
Final Answer:
Missing double curly braces around ref() -> Option D
Quick Check:
Use {{ ref('model') }} not ref('model') alone = D [OK]
Hint: Always wrap ref() in {{ }} to avoid errors [OK]
Common Mistakes:
Forgetting {{ }} around ref()
Assuming ref() works without Jinja
Removing quotes from model name
5. You have two models: customers and orders. You want to create a new model customer_orders that joins these two. Which is the best way to use ref() to ensure correct dependencies and flexible naming?
hard
A. select c.customer_id, o.order_id from customers c join orders o on c.customer_id = o.customer_id
B. select c.customer_id, o.order_id from {{ ref('customers') }} c join {{ ref('orders') }} o on c.customer_id = o.customer_id
C. select c.customer_id, o.order_id from 'customers' c join 'orders' o on c.customer_id = o.customer_id
D. select c.customer_id, o.order_id from ref('customers') c join ref('orders') o on c.customer_id = o.customer_id
Solution
Step 1: Use ref() with correct Jinja syntax for both models
To link models and ensure dbt knows dependencies, use {{ ref('model_name') }} for both customers and orders.
Step 2: Avoid hardcoding table names or missing Jinja syntax
Options A and C hardcode names or use quotes incorrectly. select c.customer_id, o.order_id from ref('customers') c join ref('orders') o on c.customer_id = o.customer_id misses curly braces, so it won't compile.
Final Answer:
select c.customer_id, o.order_id from {{ ref('customers') }} c join {{ ref('orders') }} o on c.customer_id = o.customer_id -> Option B
Quick Check:
Use {{ ref('model') }} for all dependencies = B [OK]
Hint: Use {{ ref('model') }} for all model references [OK]