Good naming helps everyone understand and find data easily. It keeps projects clear and organized as they grow.
Naming conventions at scale in dbt
-- Example naming pattern for dbt models {{ config( materialized='table', alias='stg_customers' ) }} -- File name: stg_customers.sql -- Table name: stg_customers
Use prefixes like stg_ for staging tables, int_ for intermediate, and fct_ for fact tables.
Keep names lowercase and use underscores to separate words for readability.
stg_customers to hold raw customer data.-- Staging table for raw customer data {{ config(materialized='table', alias='stg_customers') }} select * from raw.customers
int_customers_clean with only active customers.-- Intermediate table for cleaned customer data {{ config(materialized='view', alias='int_customers_clean') }} select * from {{ ref('stg_customers') }} where active = true
fct_customer_orders summarizing orders per customer.-- Fact table for customer orders {{ config(materialized='table', alias='fct_customer_orders') }} select customer_id, count(*) as order_count from {{ ref('int_customers_clean') }} join raw.orders using (customer_id) group by customer_id
This example shows a simple dbt project with three models using naming conventions: staging (stg_), intermediate (int_), and fact (fct_) tables. It helps keep the project organized and clear.
-- dbt model: stg_customers.sql
{{ config(materialized='table', alias='stg_customers') }}
select * from raw.customers
-- dbt model: int_customers_clean.sql
{{ config(materialized='view', alias='int_customers_clean') }}
select * from {{ ref('stg_customers') }} where active = true
-- dbt model: fct_customer_orders.sql
{{ config(materialized='table', alias='fct_customer_orders') }}
select customer_id, count(*) as order_count
from {{ ref('int_customers_clean') }}
join raw.orders using (customer_id)
group by customer_idConsistent naming helps when searching or filtering models in dbt Cloud or IDEs.
Use clear prefixes to quickly know the purpose of each model.
Document your naming rules in your project README for team clarity.
Use simple, consistent prefixes like stg_, int_, and fct_ to organize models.
Keep names lowercase and separate words with underscores for readability.
Good naming makes large dbt projects easier to understand and maintain.
Practice
stg_, int_, and fct_ in dbt projects?Solution
Step 1: Understand the purpose of prefixes in dbt
Prefixes likestg_(staging),int_(intermediate), andfct_(fact) indicate the role of each model.Step 2: Recognize how prefixes help in large projects
Using these prefixes organizes models logically, making it easier to find and maintain them.Final Answer:
They help organize models by their role, making the project easier to understand. -> Option BQuick Check:
Consistent prefixes = better organization [OK]
- Thinking prefixes affect performance
- Assuming prefixes create database indexes
- Believing prefixes skip tests
Solution
Step 1: Recall dbt naming style guidelines
dbt recommends lowercase letters and underscores to separate words for readability.Step 2: Evaluate each option
stg_customer_data uses lowercase and underscores, matching the recommended style.Final Answer:
stg_customer_data -> Option DQuick Check:
Lowercase + underscores = correct naming [OK]
- Using uppercase letters
- Using camelCase instead of underscores
- Starting with uppercase letters
stg_orders
int_customer_info
fct_sales_summary
stg_products
Solution
Step 1: Identify prefixes and their meanings
stg_means staging,int_means intermediate,fct_means fact table.Step 2: Match the prefix to the fact table
Onlyfct_sales_summarystarts withfct_, indicating a fact table.Final Answer:
fct_sales_summary -> Option CQuick Check:
Prefixfct_= fact table [OK]
- Confusing staging and fact prefixes
- Ignoring prefix meanings
- Choosing intermediate models as fact tables
fct_customer_orders but it contains only raw data loading logic without aggregations. What is the likely issue?Solution
Step 1: Understand prefix meanings
fct_is for fact tables, which usually contain aggregated or transactional data, not raw loads.Step 2: Match model content to prefix
Since the model only loads raw data,stg_(staging) prefix is more appropriate.Final Answer:
The model name prefixfct_is incorrect for raw data; it should bestg_. -> Option AQuick Check:
Raw data = stg_ prefix [OK]
- Assuming any prefix works for any model
- Thinking raw data belongs in fact tables
- Renaming without checking model logic
Solution
Step 1: Identify best practices for naming at scale
Consistent prefixes and lowercase with underscores improve clarity and readability.Step 2: Recognize importance of documentation
Documenting naming rules helps new team members understand conventions and dependencies quickly.Final Answer:
Use consistent prefixes likestg_,int_,fct_, keep names lowercase with underscores, and document the naming rules. -> Option AQuick Check:
Consistency + documentation = easier onboarding [OK]
- Ignoring documentation
- Using inconsistent naming styles
- Choosing unclear or numeric-only prefixes
Ready to prove it?
Pass the test and this pattern moves unknown
