What is a Model in dbt: Definition and Usage Explained
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.
select id, first_name, last_name, email from raw.customers where status = 'active'
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.