dbt Quick Reference
This quick reference collects the CLI commands, YAML configuration keys, and Jinja functions used most often day-to-day in a dbt project, meant as a lookup sheet rather than a tutorial. It assumes familiarity with dbt's core concepts — models, sources, tests, materializations — and focuses purely on exact syntax: what goes in dbt_project.yml versus schema.yml, which flags matter on dbt run, and the handful of Jinja functions (ref, source, config, var) that appear in nearly every model file.
Cricket analogy: A quick reference sheet is like a bowler's pre-match notes on a specific batter's weaknesses — not a full coaching manual, just the exact facts needed in the moment.
CLI Commands
The commands used constantly are dbt run (execute models), dbt test (run data tests), dbt build (run models, tests, seeds, and snapshots together in dependency order), dbt seed (load CSV files from the seeds/ directory), dbt snapshot (execute snapshot definitions for SCD tracking), and dbt docs generate followed by dbt docs serve (build and view the auto-generated documentation site with the full DAG). Selection flags matter just as much as the commands themselves: --select model_name targets one model, --select +model_name includes all upstream parents, --select model_name+ includes all downstream children, --select tag:nightly targets by tag, and --select state:modified+ combined with a stored manifest powers slim CI by running only changed models and their downstream dependents.
Cricket analogy: Selection flags like +model_name (upstream) versus model_name+ (downstream) are like asking a scorer for everything leading up to a wicket versus everything that happened after it — same event, opposite direction of the query.
YAML Configuration Keys
dbt_project.yml holds project-wide defaults, most commonly the models: block setting default materialization per directory, e.g. staging models as views and marts as tables. Individual model schema.yml files under models/ carry version: 2, a models: list with name, description, and columns entries, each column optionally carrying tests: (unique, not_null, relationships, accepted_values) and meta: for custom metadata. sources.yml declares external raw tables with database, schema, and tables: entries, each optionally carrying a loaded_at_field and freshness: block that powers dbt source freshness checks, which fail if upstream data hasn't landed recently enough.
Cricket analogy: sources.yml's freshness: block, which fails if data is stale, is like a fitness test cricket boards run on players, failing anyone whose match fitness hasn't been verified recently enough to be trusted on the field.
Jinja and Macros Cheatsheet
The four Jinja functions that appear in nearly every model are {{ ref('model_name') }} (reference another dbt model, builds DAG dependencies), {{ source('source_name', 'table_name') }} (reference a raw source table), {{ config(...) }} (set per-model materialization, tags, or other config inline), and {{ var('var_name', 'default') }} (read a project variable, optionally with a fallback default). Custom macros live in macros/*.sql wrapped in {% macro macro_name(arg1, arg2) %} ... {% endmacro %} and are called the same way as built-in Jinja functions; the dbt_utils package (installed via packages.yml) adds widely used ones like dbt_utils.generate_surrogate_key(), dbt_utils.date_spine(), and dbt_utils.star() that most projects rely on instead of reinventing them.
Cricket analogy: ref() and source() are like a commentator distinguishing a shot 'off a delivery from this over' (ref, internal to the match) versus 'a stat pulled from the historical record' (source, external raw data) — same broadcast, two different kinds of reference.
# dbt_project.yml
name: 'my_project'
version: '1.0.0'
config-version: 2
models:
my_project:
staging:
+materialized: view
marts:
+materialized: table
# CLI quick reference
# dbt run --select stg_orders+ # run stg_orders and everything downstream
# dbt run --select +fct_orders # run fct_orders and everything upstream
# dbt test --select tag:nightly # run only tests tagged 'nightly'
# dbt build --select state:modified+ # slim CI: changed models + downstream
# dbt docs generate && dbt docs serve # build and view the docs site
Keep this page bookmarked next to your editor during your first few weeks on a dbt project — most of what slows down new analytics engineers isn't understanding dbt's philosophy, it's forgetting the exact flag name or YAML key on the fifth model of the day.
- dbt run executes models; dbt test runs tests; dbt build runs models, tests, seeds, and snapshots together.
- --select +model runs upstream parents; --select model+ runs downstream children.
- state:modified+ powers slim CI by targeting only changed models and their downstream dependents.
- dbt_project.yml sets project-wide default materializations per model directory.
- schema.yml carries model/column descriptions and tests (unique, not_null, relationships, accepted_values).
- sources.yml's freshness: block enables dbt source freshness checks on upstream data recency.
- ref(), source(), config(), and var() are the four Jinja functions used in nearly every model.
Practice what you learned
1. What does the flag --select +fct_orders do?
2. Which command builds models, tests, seeds, and snapshots together in dependency order?
3. Where do you configure a source table's freshness check?
4. Which Jinja function reads a project-level variable with an optional default?
5. What selector combination is the foundation of dbt's slim CI feature?
Was this page helpful?
You May Also Like
dbt Best Practices
The project structure, layering, testing, and deployment conventions that keep a dbt project maintainable as it scales past a handful of models.
dbt Interview Questions
Common dbt interview questions covering concepts, materializations, testing, and macros, with the reasoning behind strong answers.
Building a Star Schema with dbt
How to design fact and dimension tables in dbt using surrogate keys, explicit grain, incremental materialization, and referential-integrity tests.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
ProgrammingPowerShell Study Notes
Programming · 30 topics