Components of a Star Schema
-
Fact Table:
- The central table in the star schema.
- Contains quantitative data (measures or metrics) such as sales, revenue, or quantity.
- Each row in the fact table represents a specific event or transaction.
- Connected to dimension tables via foreign keys.
- A fact table for a retail store might store sales transactions:
Fact_Sales:Transaction_ID,Date_ID,Product_ID,Customer_ID,Store_ID,Quantity_Sold,Total_Amount.
-
Dimension Tables:
- Surround the fact table like the points of a star.
- Contain descriptive attributes (context or metadata) related to the facts.
- Used to filter, group, or label the data in the fact table.
Dim_Date:Date_ID,Date,Month,Quarter,Year,Day_of_Week.Dim_Product:Product_ID,Product_Name,Category,Brand,Price.Dim_Customer:Customer_ID,Customer_Name,City,State,Phone_Number.Dim_Store:Store_ID,Store_Name,City,Manager_Name.
Example: Star Schema for a Retail Store
Star Schema
Fact Table
Fact_Sales
Dimension Tables
-
Dim_Date: -
Dim_Product: -
Dim_Customer: -
Dim_Store:
How the Star Schema Works
-
Querying Data:
- Suppose you want to find the total sales of sarees in Mumbai for January 2025.
- The query would join the
Fact_Salestable with theDim_Date,Dim_Product, andDim_Customertables using their respective keys. - Example SQL Query:
-
Benefits:
- Simplified Queries: The star schema makes it easy to write and understand queries.
- Improved Performance: Optimized for read-heavy analytical workloads.
- Scalability: Can handle large datasets efficiently.
Advantages of Star Schema
- Query Performance: Fewer joins are required compared to normalized schemas, leading to faster queries.
- Simplicity: Easy to design and understand, even for non-technical users.
- Flexibility: New dimensions can be added without disrupting existing queries.
- Business-Friendly: Aligns well with how business users think about data (e.g., sales, customers, products).
Disadvantages of Star Schema
- Data Redundancy: Dimension tables may contain redundant data (e.g., repeating city names in
Dim_Customer). - Limited Flexibility for Complex Relationships: Not suitable for scenarios requiring many-to-many relationships between dimensions.
- Storage Overhead: Large dimension tables can consume significant storage space.