Skip to main content

Fact vs Dimension Table

When working with data warehouse schema types, one of the most important concepts is:

๐Ÿ‘‰ Fact Table vs Dimension Tableโ€‹

Fact vs Dimension Diagram

Understanding this is the foundation of Star Schema, Snowflake Schema, and Data Modeling.


What is a Fact Table?โ€‹

A Fact Table stores:

  • Quantitative data (numbers)
  • Business metrics like:
    • sales_amount
    • quantity
    • revenue

Key Ideaโ€‹

๐Ÿ‘‰ Contains measurable values + foreign keys


What is a Dimension Table?โ€‹

A Dimension Table stores:

  • Descriptive data (text)
  • Context about facts:
    • customer_name
    • product_name
    • region

Key Ideaโ€‹

๐Ÿ‘‰ Adds meaning and context to facts


Fact vs Dimension Table (6 Key Differences)โ€‹

FeatureFact TableDimension Table
Data TypeNumericText / Descriptive
PurposeStore metricsProvide context
SizeLargeSmaller
KeysForeign keysPrimary keys
NormalizationLess importantCan be denormalized
ExampleSales, TransactionsCustomer, Product

Example of Fact and Dimension Tableโ€‹

Fact Table Example (fact_sales)โ€‹

sale_idcustomer_idproduct_idamount
1101501500
2102502300

Dimension Table Example (dim_customer)โ€‹

customer_idcustomer_namecity
101JohnNew York
102AliceLondon

Example Code (SQL)โ€‹

Query Using Fact + Dimension Tablesโ€‹

SELECT
c.customer_name,
SUM(f.amount) AS total_sales
FROM fact_sales f
JOIN dim_customer c
ON f.customer_id = c.customer_id
GROUP BY c.customer_name;

๐Ÿ‘‰ Insight:

  • Fact table provides numbers
  • Dimension table provides meaning

When to Use Fact vs Dimension Tableโ€‹

Use Fact Table when:โ€‹

  • Storing metrics / KPIs
  • Recording transactions
  • Tracking business events

Use Dimension Table when:โ€‹

  • Adding descriptive context
  • Filtering & grouping data
  • Supporting analytics queries

Performance Considerationโ€‹

  • Fact tables are large and heavily queried
  • Dimension tables are optimized for filtering
  • Proper indexing improves performance

๐Ÿ‘‰ In analytics: Fact + Dimension together = Powerful insights


Common Mistakes ๐Ÿšจโ€‹

โŒ Mixing Fact and Dimension Dataโ€‹

  • Putting text fields in fact table

โŒ Too Many Columns in Fact Tableโ€‹

  • Makes queries slow

โŒ Not Using Surrogate Keysโ€‹

  • Causes join issues

Interview Angle ๐Ÿ”ฅโ€‹

Common Questions:โ€‹

1. What is a Fact Table?
๐Ÿ‘‰ Stores measurable business data

2. What is a Dimension Table?
๐Ÿ‘‰ Stores descriptive attributes

3. What is the relationship?
๐Ÿ‘‰ Fact table joins dimension tables using keys

4. Can a fact table exist without dimensions?
๐Ÿ‘‰ Not useful in analytics


FAQโ€‹

What is fact table in simple terms?โ€‹

A fact table stores measurable business data like sales or revenue.

What is dimension table?โ€‹

A dimension table stores descriptive attributes like customer or product details.

What is difference between fact and dimension table?โ€‹

Fact table stores numbers, while dimension table provides context.

Why are both used together?โ€‹

To combine metrics + meaning for analysis.


Comparison Diagramโ€‹

Fact Table

  • Stores metrics
  • Large volume
  • Contains foreign keys
  • Used in aggregations

Dimension Table

  • Stores descriptive data
  • Smaller size
  • Contains primary keys
  • Used for filtering

Final Summaryโ€‹

  • Fact Table = Numbers (metrics) ๐Ÿ“Š
  • Dimension Table = Context (descriptions) ๐Ÿงฉ

๐Ÿ‘‰ Together, they form the backbone of data warehouse design