IntermediateLast updated: 2026-04-09 • 5 sections
Complete reference for dbt CLI commands, Jinja macros, model selection syntax, and project configuration. Covers dbt Core and dbt Cloud.
| Command | Description | Common Flags |
|---|---|---|
| dbt run | Execute all models | --select model_name, --full-refresh, --target prod |
| dbt test | Run all tests | --select model_name, --store-failures |
| dbt build | Run + test + snapshot + seed (recommended) | --select +model_name+, --full-refresh |
| dbt compile | Compile SQL without executing | --select model_name |
| dbt seed | Load CSV files from /seeds into warehouse | --select seed_name, --full-refresh |
| dbt snapshot | Execute snapshot models (SCD) | --select snapshot_name |
| dbt docs generate | Generate documentation site | (no common flags) |
| dbt docs serve | Serve docs on localhost:8080 | --port 8081 |
| dbt source freshness | Check source data freshness | --select source:source_name |
| dbt clean | Delete target/ and packages/ dirs | (no flags) |
| dbt deps | Install packages from packages.yml | (no flags) |
| dbt debug | Test connection and config | (no flags) |
| Selector | Meaning | Example |
|---|---|---|
| model_name | Single model | dbt run --select my_model |
| +model_name | Model and all upstream deps | dbt run --select +stg_orders |
| model_name+ | Model and all downstream deps | dbt run --select stg_orders+ |
| +model_name+ | Model + all upstream + downstream | dbt build --select +dim_customers+ |
| tag:tag_name | All models with tag | dbt run --select tag:daily |
| path:models/staging | All models in directory | dbt run --select path:models/staging |
| source:src_name | A source and related models | dbt source freshness --select source:raw |
| @model_name | Model + parents + children + children's parents | dbt run --select @fct_orders |
| --exclude | Exclude from selection | dbt run --select staging --exclude stg_legacy |
-- Reference another model
SELECT * FROM {{ ref('stg_customers') }}
-- Reference a source
SELECT * FROM {{ source('raw', 'orders') }}
-- Config block in model
{{ config(
materialized='incremental',
unique_key='order_id',
on_schema_change='sync_all_columns'
) }}
-- Incremental filter
{% if is_incremental() %}
WHERE updated_at > (SELECT MAX(updated_at) FROM {{ this }})
{% endif %}
-- Conditional logic
{% if target.name == 'prod' %}
{{ config(materialized='table') }}
{% else %}
{{ config(materialized='view') }}
{% endif %}
-- Loop / dynamic SQL
{% set payment_methods = ['credit_card', 'bank_transfer', 'gift_card'] %}
{% for method in payment_methods %}
SUM(CASE WHEN payment_method = '{{ method }}' THEN amount END) AS {{ method }}_amount
{% if not loop.last %},{% endif %}
{% endfor %}| Type | When to Use | Rebuild Behavior |
|---|---|---|
| view | Lightweight models, low compute, always fresh | Recreated as a SQL view on every run |
| table | Final/reporting models, heavy joins, need performance | Full drop and rebuild on every run |
| incremental | Large fact tables, append/merge new data only | Only processes new rows (with is_incremental filter) |
| ephemeral | DRY helper CTEs, no warehouse object needed | Injected as CTE into downstream models |
| snapshot | Track slowly changing dimensions (SCD Type 2) | Compares and captures changes over time |
dbt run only executes model SQL. dbt build runs models AND tests AND seeds AND snapshots in dependency order. Use dbt build as your default — it ensures tests run immediately after each model, catching issues early.
Incremental models only process new or changed rows instead of rebuilding the entire table. Use the is_incremental() macro to add a WHERE filter that selects only rows newer than the latest data in the target table. Use --full-refresh to force a complete rebuild when schema changes.
The + prefix means "include all upstream dependencies" (+model runs the model and everything it depends on). The + suffix means "include all downstream dependents" (model+ runs the model and everything that depends on it). Combine both for the full lineage: +model+.