Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. What is a dbt model?

dbt · dbt Fundamentals

What is a dbt model?

Easydbt-02
modelsqlstagingmarts

Question

What is a dbt model?

Solution

A dbt model is a SQL (or Python) file that defines one relation in the warehouse: usually a view or table that other models and BI tools can query.

Tiny example

models/staging/stg_orders.sql:

select
    id as order_id,
    customer_id,
    cast(order_date as date) as order_date,
    amount_cents / 100.0 as amount
from {{ source('raw', 'orders') }}

When you run dbt run --select stg_orders, dbt compiles the Jinja and executes something like:

create or replace view analytics.stg_orders as (
  select ... from raw.orders
);

Mental model

One model file  ≈  one named dataset in the warehouse
       |
       +-- depends on sources and/or other models
       +-- materializes as view / table / incremental / ephemeral

Common project layers

  • staging/: light cleanup, renaming, typing (1:1 with sources)
  • intermediate/: reusable business logic
  • marts/: facts and dimensions for consumers

Interview tip: The model is the *definition* of the dataset. Materialization (view vs table vs incremental) is a separate config choice about how that definition is stored and refreshed.

PreviousNext