SynfraCore
Synfracore
Start Learning
Navigation

Academies

Platform

RoadmapsLabsCertificationsInterviewPYQsAI AssistantCareer
Start Learning Free🗺️ Learning Roadmaps

dbtCheatsheets

Quick reference — commands, syntax, and patterns

✍️
Written by senior engineers. Reviewed for technical accuracy.· Updated 2025 · SynfraCore dbt Team
Expert Content

dbt — Quick Reference

Core CLI commands

bash
dbt run                          # build all models
dbt test                         # run all tests
dbt build                        # run + test, in dependency order (recommended default)
dbt seed                         # load CSV seed files as tables
dbt docs generate && dbt docs serve   # generate + serve documentation/lineage

dbt run --select my_model        # build just one model
dbt run --select my_model+       # build the model + everything downstream of it
dbt run --select +my_model       # build the model + everything upstream of it
dbt run --full-refresh           # force a full rebuild of incremental models

`ref()` and `source()`

sql
{{ ref('stg_orders') }}                -- reference another dbt model
{{ source('raw', 'orders') }}          -- reference a raw source table (declared in sources.yml)
{{ this }}                             -- reference the current model's own table (used in incremental logic)

Materializations

TypeBehaviorTypical use

|---|---|---|

`view`Recomputed on every queryStaging models — cheap, always fresh
tableFully rebuilt every runMarts queried repeatedly by BI
incrementalOnly processes new/changed rowsLarge fact tables

Incremental model pattern

sql
{{ config(materialized='incremental', unique_key='order_id') }}

SELECT * FROM {{ source('raw', 'orders') }}
{% if is_incremental() %}
  WHERE updated_at > (SELECT max(updated_at) FROM {{ this }})
{% endif %}

Tests

yaml
# Generic tests (schema.yml)
models:
  - name: stg_orders
    columns:
      - name: order_id
        tests: [unique, not_null]
      - name: status
        tests:
          - accepted_values:
              values: ['pending', 'shipped', 'delivered']
      - name: customer_id
        tests:
          - relationships:
              to: ref('stg_customers')
              field: customer_id
sql
-- Singular test (tests/assert_positive_totals.sql)
-- Fails if it returns any rows
SELECT order_id FROM {{ ref('fct_orders') }} WHERE total_amount < 0

Project structure convention

models/
├── staging/       -- one model per source, light cleaning only
├── intermediate/  -- reusable logic shared across marts
└── marts/         -- business-logic models consumed by BI tools

Slim CI (state-based selection)

bash
dbt build --select state:modified+ --state ./prod-run-artifacts

Macro example

sql
{% macro cents_to_dollars(column_name) %}
    ({{ column_name }} / 100.0)
{% endmacro %}

Troubleshooting quick checks

bash
dbt ls --select +model_name+   # trace a model's full upstream/downstream deps
dbt source freshness           # check if source data is stale/schema drifted
dbt run --full-refresh --select model_name   # fix accumulated incremental duplicates
Share:
Join our Community
Daily tips, job alerts, interview help — join engineers learning together
Also Worth Exploring
← Back to all dbt modules
CertificationNotes