Fact and Dimension Table
1. Introduction
In data warehousing, data is structured into Fact Tables and Dimension Tables to facilitate efficient querying and analysis. This structure follows the Star Schema or Snowflake Schema, enabling faster reporting and analytics.
2. Fact Table
A Fact Table stores business transactions or events and contains numeric measures (also called facts) along with foreign keys linking to dimension tables.
Key Characteristics of a Fact Table:
Types of Fact Tables
3. Dimension Table
A Dimension Table stores descriptive, textual, or categorical data that provides context for facts. They help slice and dice the numerical data in meaningful ways.
Key Characteristics of a Dimension Table:
Types of Dimension Tables
4. Star Schema vs. Snowflake Schema
1. Star Schema
Example:
Date_Dim
|
Product_Dim -- Sales_Fact -- Customer_Dim
|
Store_Dim
Recommended by LinkedIn
2. Snowflake Schema
Example:
Date_Dim
|
Product_SubCategory_Dim -- Product_Dim -- Sales_Fact -- Customer_Dim
|
Store_Dim
5. Example Query
Question: Find total sales per product for March 2024.
SELECT
p.Product_Name,
SUM(f.Sales_Amount) AS Total_Sales
FROM Sales_Fact f
JOIN Product_Dim p ON f.Product_ID = p.Product_ID
JOIN Date_Dim d ON f.Date_ID = d.Date_ID
WHERE d.Month = 'March' AND d.Year = 2024
GROUP BY p.Product_Name;
7. Real-World Examples
Retail (Amazon, Walmart)
Finance (Banking, Insurance)
Healthcare (Hospital Data)
8. Conclusion
For more details follow my series
For more interesting blog follow me :