Skip to main content

Data Modelling

Updated Nov 29, 2021 ·

Data Models

Data models define how data is structured in a database. Two common models for data warehouses are star schema and snowflake schema. These models help organize data for analysis by separating it into fact tables and dimension tables.

Fact Table

A fact table stores measurements or metrics about business processes.

  • Each row represents a transaction.
  • Contains numeric values like sales quantity and tax.
  • Includes foreign keys linking to dimension tables.

Example: ABC Enterprise, a home office furniture company, tracks sales orders in a fact table:

Sales_Order_Fact table:

CustomerIDProductIDDateIDUnitSoldSalesAmountTax
101501202401250025
102305202402120010
103701202403375037.5
1042022024045120060
105608202405480040

Dimension Table

Dimension tables store descriptive attributes related to the fact table.

  • Provide details like customer name, location, or product type.
  • Help categorize and analyze data.
  • Are linked to the fact table through foreign keys.

Example: Customer dimension table:

Product_Dim table:

ProductIDLotCodeColorDescriptionModel
202L100BlackOffice ChairX1
305L200WhiteDesk LampY2
501L300GrayStanding DeskZ3
608L400SilverMonitorA4
701L500BrownBookshelfB5

Customer_Dim table:

CustomerIDNameAccountNumLoyaltyIDCountryEmail
101JohnACC1001L001USAjohn@email.com
102LisaACC1002L002UKlisa@email.com
103AlexACC1003L003USAalex@email.com
104EmmaACC1004L004Canadaemma@email.com
105RyanACC1005L005Germanyryan@email.com

Time_Dim table:

DateIDYearQuarterMonthDayOfWeek
2024012024Q1JanMonday
2024022024Q1FebTuesday
2024032024Q1MarWednesday
2024042024Q2AprThursday
2024052024Q2MayFriday

Star Schema

A star schema has a single fact table linked to multiple dimension tables.

  • Simple structure, fast queries.
  • Easy to understand and use.

This layout makes queries fast and efficient.

Snowflake Schema

A snowflake schema is an extension of the star schema where some dimensions are further normalized.

  • At least one dimension table is split into smaller tables.
  • Requires more joins but reduces redundancy.

This structure provides more flexibility but may slow down queries due to extra joins.

Example: Instead of storing customer country in the Customer table, we create a separate Country table.