01. What Are DBT Models?
The Core of DBT: Models
In DBT, a model is the absolute core building block of your project. If you understand models, you understand DBT.
Simply put: A DBT model is a single .sql file containing a single SELECT statement.
1. The "No DDL" Rule
In traditional Data Engineering, creating a new table required writing boilerplate DDL (Data Definition Language) like this:
-- The Old Way (Manual DDL)
CREATE OR REPLACE TABLE analytics.customers AS (
SELECT id, name, email
FROM raw.users
);
DBT completely abstracts this away. You never write CREATE TABLE or INSERT INTO. You only write the business logic:
-- The DBT Way (Just the SELECT)
SELECT
id,
name,
email
FROM {{ source('raw', 'users') }}
DBT handles the boilerplates, the wrapping, and the execution on your behalf.
️ 2. How Models Work (Under the Hood)
When you run the command dbt run, DBT performs a two-step process:
- Compilation: DBT reads your
.sqlfile, evaluates any Jinja macros (like{{ ref() }}), and writes the final, raw SQL query into the hiddentarget/folder. - Execution: DBT takes that compiled query, wraps it in the appropriate
CREATE VIEWorCREATE TABLEstatement, and pushes it to Snowflake (or your configured warehouse).
3. Where Do Models Live?
By default, every single model must be saved inside the models/ directory of your DBT project.
- Subdirectories inside
models/(likemodels/staging/ormodels/marts/) help keep things organized, but DBT will recursively search the entire folder to find your models. - The name of the
.sqlfile becomes the exact name of the table or view in your database. (If you name your filedim_customers.sql, DBT will create a table nameddim_customers).
Summary
Models force you to think entirely about the transformation logic (the "T" in ELT) rather than worrying about the painful database administration steps of creating, dropping, and altering tables.