dbt Tutorial
Learn dbt step by step: 41 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is dbt? Learn what dbt (data build tool) does, why analytics teams use it, how it fits into ELT, and what you can and cannot run on this site while following the course.
- Installing dbt and Setting Up a Project Install dbt Core with pip, choose an adapter, run dbt init, and understand profiles.yml targets and connection settings, with a runnable stand-in for target selection.
- Your First dbt Run Write your first two dbt models, run them with dbt run, see how dbt compiles SQL into the target folder, and reproduce the generated CREATE VIEW statements here.
- The dbt Command Line A tour of the dbt commands you use every day: run, test, build, compile, show, ls, seed, snapshot, docs, retry, clean and the flags that work across them.
- How dbt Works: Architecture, Core, Cloud and Fusion Understand what happens inside a dbt command (parse, compile, execute), how the dependency graph is built, and how dbt Core, dbt Cloud and Fusion differ.
Projects and Models
- Project Structure and dbt_project.yml Learn every folder in a dbt project and how dbt_project.yml configures paths, folder-level settings, variables and hooks, with a runnable config-resolution stand-in.
- Writing Models and Using ref() Write dbt models as SELECT statements, connect them with ref(), follow the import-CTE style, and learn why ref() beats hard-coded table names across environments.
- Materializations: View, Table and Ephemeral Learn how dbt materializations decide whether a model becomes a view, a table or an inlined CTE, how to configure them, and how to choose between them with trade-offs.
- Staging, Intermediate and Marts Layers Organize a dbt project into staging, intermediate and marts layers, with naming rules, what belongs in each layer, and a complete runnable example on shop data.
- Model Configs and Properties Learn the three places to configure dbt models, how precedence works, and the settings you use daily: materialized, schema, alias, tags, enabled, hooks and meta.
- Selecting Nodes: --select, Graph Operators and Tags Master dbt node selection syntax: model names, the + and @ graph operators, tags, paths, resource types, intersections, exclusions, YAML selectors and state:modified.
Sources, Seeds and Snapshots
- Sources and Freshness Declare raw tables as dbt sources, read them with source(), add tests and descriptions, and monitor data freshness with loaded_at_field, warn_after and error_after.
- Seeds: Version-Controlled CSV Data Load small CSV files into your warehouse with dbt seed, reference them with ref(), set column types, quote and delimiter options, and know when seeds are the wrong tool.
- Snapshots: Tracking Changing Data Learn how dbt snapshots record how rows change over time using dbt_valid_from and dbt_valid_to, configure them in YAML, run dbt snapshot, and see the mechanism in SQL.
- Snapshot Strategies, Hard Deletes and SCD2 Compare dbt snapshot strategies timestamp and check, handle deleted source rows with hard_deletes, join facts to snapshot history, and learn slowly changing dimension types.
Jinja and Macros
- Jinja Basics for dbt Learn the three Jinja delimiters used in dbt, set variables, use filters and string operations, and see how Jinja renders SQL, all with the real Jinja library running here.
- Control Flow and Loops in Jinja Use Jinja if statements, for loops, the loop variable, dictionaries and namespaces to generate repetitive SQL in dbt, and run the rendered SQL on sample data.
- Writing Macros Create dbt macros to reuse SQL logic: arguments, default values, calling macros from models, macro files, docs, tests with macros, run-operation and common mistakes.
- dbt Context Functions: target, var, env_var and Friends Learn the functions and objects dbt adds to Jinja: target, var, env_var, this, config, execute, run_query, log, exceptions and run_started_at, with a runnable stand-in context.
- Macro Patterns: Cross-Database Macros, run_query and Overrides Advanced dbt macro patterns: write cross-database macros with adapter.dispatch, generate pivots from data with run_query, override built-in macros, and keep macros testable.
Tests and Documentation
- Generic Tests: unique and not_null Learn how dbt generic tests work: declare unique and not_null in YAML, see the SQL dbt really runs, and run the same checks in your browser.
- Relationships and accepted_values Tests Use dbt's relationships test to protect foreign keys and accepted_values to guard category columns. Includes the SQL behind each test, runnable in your browser.
- Singular and Custom Generic Tests Write your own dbt tests: one-off singular tests in tests/, and reusable generic tests with Jinja. Business rules become SQL you can run in your browser.
- Test Severity, store_failures and Selection Control how dbt tests behave: warn vs error, thresholds, where filters, storing failing rows, and selecting tests by model, tag or test type.
- Documenting Models with YAML and Doc Blocks Write dbt documentation that stays useful: model and column descriptions in YAML, reusable doc blocks in Markdown, meta fields and persisting docs to the warehouse.
- dbt docs, Lineage and Exposures Generate and serve the dbt documentation site, read the lineage graph, understand manifest and catalog files, and declare exposures for dashboards.
Incremental Models and Materializations
- Materializations: View, Table and Ephemeral Understand how dbt turns a SELECT into a view, table or ephemeral CTE, how to configure it per model or folder, and how to choose between them.
- Incremental Models: the Basics Build big tables faster with dbt incremental models: is_incremental(), the {{ this }} reference, unique_key, and a runnable simulation of the pattern.
- Incremental Strategies: merge, delete+insert, microbatch Compare dbt's incremental strategies: append, merge, delete+insert, insert_overwrite and microbatch. See the SQL each one runs and how to choose.
- Late-Arriving Data and Full Refresh Keep incremental models correct when rows arrive late or change: lookback windows, deduplication, on_schema_change and when to use dbt run --full-refresh.
Packages and Deployment
- Packages and dbt_utils Install dbt packages with packages.yml and dbt deps, pin versions safely, and use dbt_utils macros and tests such as surrogate keys and unique combinations.
- Environments, Targets and Profiles Separate dev and production in dbt with profiles.yml targets, env_var(), custom schemas and generate_schema_name. Includes a runnable schema-naming stand-in.
- Deploying dbt: Jobs and Scheduling Run dbt in production: choose job commands, schedule with cron, dbt Cloud, Airflow or GitHub Actions, use source freshness, retries and run artifacts.
CI and Best Practices
- CI with Slim CI and State Selection Test every pull request safely: build only changed models with state:modified+, defer to production, clone data, and add CI checks for docs and style.
- Project Structure and Naming Conventions Organize a dbt project in layers: staging, intermediate and marts, with naming conventions, folder configs, one-to-one staging models and a DAG you can reason about.
- Model Contracts, Versions and Performance Make dbt marts safe to depend on: enforced contracts, constraints, model versions, access modifiers, groups, and performance habits that keep builds fast.
Projects and Practice
- Project: Shop Analytics Pipeline Design a complete dbt project for an online shop: sources, staging, intermediate and mart models, tests and docs, with every SQL layer runnable in your browser.
- Project: Incremental Events Model Build a clickstream-style incremental dbt model with a loaded_at filter, lookback window, deduplication and a daily rollup, simulating three runs in SQL.
- Project: Testing and Quality Gates Plan a test strategy for a dbt project: test pyramid, coverage report, custom tests, severity rules, freshness and CI gates, with runnable SQL checks on the shop data.
- dbt Practice Exercises Twelve dbt exercises on tests, documentation, materializations, incremental logic, packages and CI, with solutions. SQL parts run in your browser.
- dbt Interview Questions and Answers Prepare for analytics engineering interviews: 25 dbt questions and clear answers on models, tests, incremental logic, packages, deployment, CI and design.