0Pricing
SQL Academy · Lesson

DBT (Data Build Tool) Fundamentals

Model warehouse data as SELECT statements in dbt, with refs, sources, and incremental models.

DBT (Data Build Tool) Fundamentals is a free SQL Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SQL Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What dbt Is

dbt is the "T" in ELT: it transforms data inside your warehouse using SELECT statements. You define models (SELECTs) and dbt materialises them as tables or views, manages dependencies, and runs tests.

Why dbt?

Before dbt, transformations lived in ad-hoc SQL scripts, stored procedures, or Python jobs. dbt brings:

  • Modular SQL as code, versioned in Git
  • Dependency graph (ref()) instead of manual ordering
  • Tests as first-class objects
  • Documentation generation

Project Structure

A dbt project:

my_project/
  dbt_project.yml
  models/
    staging/
      stg_orders.sql
    marts/
      fct_revenue.sql
  tests/
  seeds/
  macros/

A Model File

Just a SELECT in a .sql file:

-- models/staging/stg_orders.sql
{{ config(materialized='view') }}
SELECT
  id,
  user_id,
  total,
  created_at
FROM {{ source('raw', 'orders') }}

Materialisation Types

  • view — dbt creates a VIEW; fast to update, slower to query
  • table — full table; rebuilt every run
  • incremental — only new rows added
  • ephemeral — inlined CTE, no DB object

ref() and Dependencies

Reference one model from another:

-- models/marts/fct_revenue.sql
SELECT
  date_trunc('day', created_at) AS day,
  SUM(total) AS revenue
FROM {{ ref('stg_orders') }}
GROUP BY 1

Running dbt

Build the whole project:

dbt run                    # build all models
dbt run --select staging   # subset
dbt run --select +fct_revenue   # this model and upstream
dbt build                   # run + test

Sources

Sources document and reference the raw tables:

# models/sources.yml
sources:
  - name: raw
    database: warehouse
    tables:
      - name: orders

Incremental Models

For huge fact tables:

{{ config(materialized='incremental', unique_key='id') }}
SELECT *
FROM {{ source('raw','orders') }}
{% if is_incremental() %}
  WHERE created_at > (SELECT MAX(created_at) FROM {{ this }})
{% endif %}

Jinja Templating

dbt is SQL + Jinja, so you can loop and conditionally generate SQL:

{% set tiers = ['free','pro','enterprise'] %}
SELECT user_id,
{% for t in tiers %}
  COUNT(*) FILTER (WHERE tier = '{{ t }}') AS {{ t }}_count {% if not loop.last %},{% endif %}
{% endfor %}
FROM users GROUP BY user_id

Snapshots

Slowly-changing dimensions captured automatically:

{% snapshot user_snapshot %}
  {{ config(
    target_schema='snapshots',
    unique_key='id',
    strategy='timestamp',
    updated_at='updated_at',
  ) }}
  SELECT * FROM {{ source('raw','users') }}
{% endsnapshot %}

Documentation

Auto-generate browsable docs from your models + YAML descriptions:

dbt docs generate
dbt docs serve     # opens browser

Recap

dbt models data transformations as SQL code.

  • Model = SELECT in a .sql file
  • ref() builds the DAG
  • Materialisations: view / table / incremental / ephemeral
  • Tests and docs as first-class

Quick Check

What does dbt's {{ ref('stg_orders') }} do?

Frequently asked questions

Is the “DBT (Data Build Tool) Fundamentals” lesson free?

Yes — the full text of “DBT (Data Build Tool) Fundamentals” is free to read here on the web, and the SQL Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SQL Academy course, upgrade to CoddyKit PRO.

What will I learn in “DBT (Data Build Tool) Fundamentals”?

Model warehouse data as SELECT statements in dbt, with refs, sources, and incremental models. You practise SQL Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SQL Academy?

No prior experience is required. SQL Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “DBT (Data Build Tool) Fundamentals” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SQL Academy lesson?

Yes. Every SQL Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. DBT (Data Build Tool) Fundamentals
  2. SQLFluff and Linting
  3. Testing SQL: dbt tests, Great Expectations
  4. CI for Schema Changes (GitHub Actions)
← Back to SQL Academy