0
0
dbtdata~10 mins

Why models are the core of dbt - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why models are the core of dbt
Write SQL SELECT query
Create a dbt model file (.sql)
dbt compiles model into SQL
dbt runs model to create table/view
Model becomes a reusable dataset
Other models can reference this model
Builds a dependency graph
Enables incremental, testing, documentation
Models in dbt are SQL files that define datasets. They are compiled and run to create tables or views, forming the core reusable data building blocks.
Execution Sample
dbt
select * from raw.sales
where sale_date >= '2024-01-01'
This SQL defines a model that filters sales data from January 1, 2024 onward.
Execution Table
StepActionInput/StateOutput/Result
1Write SQL queryRaw sales tableSQL query with filter on sale_date
2Save as model fileSQL queryFile models/sales_filtered.sql created
3dbt compileModel fileCompiled SQL ready for execution
4dbt runCompiled SQLTable/view sales_filtered created in warehouse
5Reference modelsales_filteredOther models can use sales_filtered as source
6Build dependency graphAll modelsGraph showing model dependencies
7Enable testing and docsModels and graphTests and docs generated for models
💡 All models compiled and run, dependency graph built, enabling testing and documentation
Variable Tracker
VariableStartAfter Step 2After Step 4Final
SQL queryNoneselect * from raw.sales where sale_date >= '2024-01-01'SameSame
Model fileNonemodels/sales_filtered.sql createdSameSame
Compiled SQLNoneNoneCompiled SQL readySame
Table/view in warehouseNoneNonesales_filtered createdSame
Dependency graphEmptyEmptyEmptyGraph with sales_filtered node
Key Moments - 3 Insights
Why do we write SQL files as models instead of running SQL directly?
Because dbt compiles and runs these SQL files to create reusable tables or views, enabling dependency management and testing, as shown in steps 1-4 of the execution table.
How does referencing one model in another help?
Referencing builds a dependency graph (step 6), so dbt knows the order to run models and can manage incremental updates and testing.
What happens after dbt runs a model?
The model creates a table or view in the data warehouse (step 4), which becomes a dataset other models or analysts can use.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is created after step 4?
AA table or view in the warehouse
BA compiled SQL file
CA dependency graph
DA test report
💡 Hint
Check the Output/Result column at step 4 in the execution table
At which step does dbt build the dependency graph?
AStep 3
BStep 6
CStep 5
DStep 7
💡 Hint
Look for 'Build dependency graph' in the Action column of the execution table
If you change the SQL query in the model file, which step must you run again to update the table?
AStep 1
BStep 3
CStep 4
DStep 7
💡 Hint
Step 4 runs the compiled SQL to create or update the table/view
Concept Snapshot
dbt models are SQL files defining datasets.
They compile into SQL run in your warehouse.
Models create tables or views.
Models build a dependency graph.
This enables testing, docs, and incremental builds.
Full Transcript
In dbt, models are the core because they are SQL files that define datasets. You write a SQL query and save it as a model file. dbt compiles this SQL and runs it to create tables or views in your data warehouse. These tables become reusable datasets. Other models can reference these datasets, which builds a dependency graph. This graph helps dbt run models in the right order and supports testing and documentation. The execution steps show writing SQL, saving as a model, compiling, running to create tables, referencing models, building the graph, and enabling tests and docs. Understanding this flow helps beginners see why models are central to dbt's power.