Skip to main content
InterviewHubPRO
Section Overview
Q3

Question 3 of 50

Part 1: dbt Core Concepts & Fundamentals (Junior / Entry-Level)

6%
dbt Analytics Engineering (50 Qs)•Part 1: dbt Core Concepts & Fundamentals (Junior / Entry-Level)

What is the `ref()` function and why is it revolutionary?

junior LevelCode ExampleVue & Nuxt

In Simple Words: In traditional SQL pipelines, queries hardcode physical table names (SELECT * FROM analytics_prod.dim_customers). If you switch to a development schema, your queries break or accidentally overwrite production! ref('model_name') is dbt's dependency resolution function:

  1. Builds the DAG (Directed Acyclic Graph): dbt reads all ref() calls and automatically determines the exact order in which models must be built.
  2. Environment Agnostic: In development, ref('stg_orders') compiles to dev_manth.stg_orders. In production, it compiles to analytics.stg_orders without changing a single line of SQL!
sql
-- models/marts/fct_orders.sql
SELECT 
  o.order_id,
  o.customer_id,
  c.customer_name,
  o.order_total
FROM {{ ref('stg_orders') }} o
JOIN {{ ref('dim_customers') }} c ON o.customer_id = c.customer_id