0
0
DbtConceptBeginner · 3 min read

What is a Model in dbt: Definition and Usage Explained

In dbt, a model is a SQL file that defines a transformation on your raw data to create a new table or view in your data warehouse. Models are the core building blocks in dbt that let you organize and run your data transformations in a clear, reusable way.
⚙️

How It Works

Think of a dbt model like a recipe in a cookbook. Each recipe (model) tells you how to take raw ingredients (raw data) and turn them into a finished dish (clean, transformed data). When you run dbt, it follows these recipes to prepare your data step-by-step.

Technically, a model is a SQL SELECT statement saved as a file. When dbt runs, it runs this SQL and creates a table or view in your database with the results. This lets you build complex data transformations by chaining models together, where one model can use the output of another.

This approach helps keep your data organized and easy to maintain, just like having clear recipes makes cooking easier and more consistent.

💻

Example

This example shows a simple dbt model that selects customer data and filters for active customers only.

sql
select
  id,
  first_name,
  last_name,
  email
from raw.customers
where status = 'active'
Output
id | first_name | last_name | email ---|------------|-----------|------------------- 1 | Alice | Smith | alice@example.com 2 | Bob | Jones | bob@example.com
🎯

When to Use

Use dbt models whenever you need to transform raw data into a clean, analysis-ready format. For example:

  • Cleaning and filtering raw data
  • Joining multiple tables to create a unified dataset
  • Calculating new metrics or aggregations
  • Building reusable data layers for dashboards and reports

Models help you break down complex data workflows into manageable pieces that are easy to test and update.

Key Points

  • A dbt model is a SQL file that creates a table or view in your data warehouse.
  • Models define data transformations in a clear, reusable way.
  • They help organize complex data workflows by chaining transformations.
  • Running dbt executes these models to build your transformed data.

Key Takeaways

A dbt model is a SQL file that transforms raw data into a new table or view.
Models let you organize and chain data transformations clearly and efficiently.
Use models to clean, join, and prepare data for analysis and reporting.
Running dbt executes all models to build your final transformed datasets.