Member-only story
dbt Models: A Practical Guide
👉 Not a Medium member? Here’s a link for you!🌟
1. What is a dbt model?
A dbt model is a single .sql file that contains one select statement. dbt turns that query into a table or view in your warehouse. You write the transformation logic, and dbt handles the create table as / create view as boilerplate, dependency ordering, and environment-specific naming.
-- models/staging/stg_orders.sql
select
id as order_id,
user_id as customer_id,
order_date,
status
from {{ source('shop', 'raw_orders') }}Key rules:
- One model = one
selectstatement = one file. - The file name is the model name (
stg_orders.sqlcreatesstg_orders). - Models are written in SQL plus Jinja (
{{ ... }}and{% ... %}). - Models live in the
models/directory (configurable indbt_project.yml).
2. Building blocks inside a model
{{ source('src', 'table') }}Points at a raw table loaded outside dbt.{{ ref('model') }}Points at another dbt model and creates a dependency.{{ config(...) }}Sets options for this model at the top of the file.{{ var('name') }}Reads a project variable.









