0
0
dbtdata~5 mins

One model per source table rule in dbt

Choose your learning style9 modes available
Introduction

This rule helps keep your data organized and easy to understand. It means you create one dbt model for each source table, so your work stays simple and clear.

When you want to keep your data transformations easy to follow.
When you have many source tables and want to avoid confusion.
When you want to make debugging and testing easier.
When you want to build a clear and maintainable data pipeline.
When collaborating with others who need to understand your data models.
Syntax
dbt
models/
  source_table_1.sql
  source_table_2.sql
  ...

Each model file corresponds to one source table.

Model names usually match source table names for clarity.

Examples
This model selects all data from the 'customers' source table.
dbt
-- models/customers.sql
select * from {{ source('raw', 'customers') }}
This model selects all data from the 'orders' source table.
dbt
-- models/orders.sql
select * from {{ source('raw', 'orders') }}
Sample Program

This example shows two dbt models, each representing one source table: 'customers' and 'orders'. Each model simply selects all data from its source table.

dbt
-- models/customers.sql
select * from {{ source('raw', 'customers') }};

-- models/orders.sql
select * from {{ source('raw', 'orders') }};
OutputSuccess
Important Notes

Following this rule makes your project easier to maintain and understand.

You can still create additional models that join or transform these base models.

Summary

Create one dbt model per source table to keep things simple.

This helps with clarity, debugging, and teamwork.

Base models can be used to build more complex transformations later.