0
0
dbtdata~10 mins

Model naming conventions in dbt - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Model naming conventions
Start: Define model purpose
Choose clear, descriptive name
Use lowercase letters and underscores
Avoid spaces and special characters
Add prefixes/suffixes if needed (e.g., stg_, int_, fct_)
Check for uniqueness in project
Save model with chosen name
Use name consistently in references
This flow shows how to pick clear, consistent names for dbt models to keep projects organized and easy to understand.
Execution Sample
dbt
stg_customers.sql
int_orders.sql
fct_sales.sql
Example model file names showing common prefixes for staging, intermediate, and fact models.
Execution Table
StepActionInput/NameValidationResult
1Define model purposeCustomer raw dataPurpose clearProceed
2Choose descriptive namestg_customersLowercase, underscoresValid
3Check for spaces/special charsstg_customersNo spaces or special charsValid
4Add prefix for layerstg_Prefix matches staging layerValid
5Check uniquenessstg_customersNo duplicate model namesUnique
6Save model filestg_customers.sqlFile saved with correct nameSuccess
7Use name in referencesref('stg_customers')Matches model file nameReference works
8EndNaming convention followed
💡 All steps passed, model named correctly following conventions.
Variable Tracker
VariableStartAfter Step 2After Step 4Final
model_namestg_customersstg_customersstg_customers
Key Moments - 3 Insights
Why do we use prefixes like 'stg_' or 'fct_' in model names?
Prefixes help identify the model's role or layer in the project, making it easier to organize and understand the data flow. See execution_table steps 4 and 5.
Can model names have spaces or capital letters?
No, model names should be lowercase and use underscores instead of spaces to avoid errors and keep consistency. See execution_table step 3.
What happens if two models have the same name?
It causes conflicts and errors in dbt. Always check for uniqueness before saving. See execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what prefix is used for staging models?
Astg_
Bint_
Cfct_
Draw_
💡 Hint
Check Step 4 in the execution_table where prefix is added.
At which step is the model name checked for spaces or special characters?
AStep 2
BStep 5
CStep 3
DStep 6
💡 Hint
Look at the 'Validation' column in execution_table for Step 3.
If a model name had uppercase letters, which step would fail?
AStep 1
BStep 2
CStep 3
DStep 5
💡 Hint
Step 2 checks for lowercase letters and underscores.
Concept Snapshot
Model naming conventions in dbt:
- Use clear, descriptive names
- Use lowercase letters and underscores
- Avoid spaces and special characters
- Add prefixes like stg_, int_, fct_ for layers
- Ensure names are unique in the project
- Use consistent names in references
Full Transcript
This visual execution shows how to name dbt models properly. First, decide what the model does. Then pick a clear name using lowercase letters and underscores. Avoid spaces or special characters. Add a prefix like stg_ for staging models to show their role. Check that the name is unique in your project to avoid conflicts. Save the model file with this name and use it consistently when referencing the model in your dbt project. Following these steps keeps your project organized and easy to understand.