Data Modelling in Warehouses: Facts, Dimensions and a Worked Star Schema
Learn to set a warehouse grain, separate facts from dimensions, reconcile a four-row sales model, and preserve a customer's historical city with Type 2 rows.
KnowledgeGate Team
Exam prep & CS education

Knowing that a data warehouse contains tables is not enough. You must decide what one fact row represents, which attributes belong in dimensions, and why a historical report should not change after a customer moves city. One four-row retail-sales model checks totals, schema choices, and exam traps.
Data warehouse modelling starts with the grain
Operational models record transactions safely. Analytical models answer repeated questions across time, product, store, and customer. Normalisation is not wrong in a warehouse; workload and history requirements guide the design.
The grain comes first: one row in FactSales per completed order line. An order with three products therefore produces three fact rows. If the same product appears on two separate completed lines, it produces two rows.
This model must answer net sales and units by calendar day, product category, store city, and the customer's city when the sale occurred. Changing the grain later changes what can be counted safely, so declare it before selecting columns.
Facts, dimensions and keys in one star schema
A fact table records events at the declared grain. FactSales contains order_line_id, date_key, product_key, store_key, customer_key, quantity, unit_price, gross_sales, discount, and net_sales. order_line_id is a degenerate dimension: it traces a line without an almost-empty order-line dimension.
Dimensions supply descriptive context:
DimDate:(20260105, 2026-01-05, Jan, Q1)and(20260106, 2026-01-06, Jan, Q1)DimProduct:(101, P-17, DBMS Handbook, Books)and(102, P-29, SQL Practice Cards, Study Aids)DimStore:(11, DEL-01, Delhi, North)and(12, LKO-01, Lucknow, North)DimCustomer:(501, C42, Jaipur),(502, C77, Delhi), and(503, C88, Lucknow)
Names, cities, and categories belong in dimensions, not every fact row. Surrogate keys such as product_key = 101 identify warehouse rows; business keys such as product_id = P-17 identify source entities. For the broader ETL, OLAP, and data-mining workflow, use Data Mining and Data Warehouse Explained. The order-line grain, measure additivity, and Type 2 history here focus specifically on dimensional-model design.
Worked star schema example: load four rows and reconcile them

The four completed order lines are:
Line | Date key | Product | Store | Customer | Quantity | Unit price | Gross sales | Discount | Net sales |
|---|---|---|---|---|---|---|---|---|---|
OL-9001 | 20260105 | 101 | 11 | 501 | 2 | 600 | 1,200 | 100 | 1,100 |
OL-9002 | 20260105 | 102 | 12 | 502 | 1 | 800 | 800 | 0 | 800 |
OL-9003 | 20260106 | 101 | 12 | 503 | 3 | 600 | 1,800 | 150 | 1,650 |
OL-9004 | 20260106 | 102 | 11 | 501 | 2 | 800 | 1,600 | 100 | 1,500 |
For each row, gross_sales = quantity × unit_price, then net_sales = gross_sales - discount:
OL-9001:
2 × 600 = 1,200;1,200 - 100 = 1,100.OL-9002:
1 × 800 = 800;800 - 0 = 800.OL-9003:
3 × 600 = 1,800;1,800 - 150 = 1,650.OL-9004:
2 × 800 = 1,600;1,600 - 100 = 1,500.
Now reconcile the whole fact table. Quantity is 2 + 1 + 3 + 2 = 8. Gross sales are 1,200 + 800 + 1,800 + 1,600 = 5,400. Discount is 100 + 0 + 150 + 100 = 350, so net sales are 5,400 - 350 = 5,050.
The dimensions roll up these facts without changing their grain. On 5 January, the two rows give 3 units and net sales of 1,100 + 800 = 1,900. On 6 January, they give 5 units and 1,650 + 1,500 = 3,150. Product 101 contributes 1,100 + 1,650 = 2,750; product 102 contributes 800 + 1,500 = 2,300.
Realised net sales per unit are SUM(net_sales) / SUM(quantity) = 5,050 / 8 = 631.25. Summing the four unit_price values gives 2,800, but that number has no useful sales meaning.
Star schema versus snowflake schema
In the star version, category_name stays in DimProduct. Grouping facts by category follows FactSales -> DimProduct, one join from the fact. In a snowflake, product 101 points to category_key 7 and product 102 to key 8; DimCategory stores (7, Books) and (8, Study Aids). The path becomes FactSales -> DimProduct -> DimCategory, two joins from the fact.
The star repeats category attributes across product rows and gives a flatter query path. The snowflake stores a category once and represents its hierarchy separately. Neither is universally faster, smaller, or more correct; workload, engine, cardinality, and maintenance rules matter. Normalization in DBMS: 1NF to BCNF contrasts normal forms with controlled denormalisation, but it is not a warehouse-specific rule.
Additive, semi-additive and non-additive measures
In this model, quantity, gross_sales, discount, and net_sales are additive across date, product, and store. unit_price is not a total. The overall realised value must be SUM(net_sales) / SUM(quantity) = 631.25, not an unweighted average of row or product averages.
Now consider a snapshot fact. Product 101 has an inventory_balance of 40 units at the end of 5 January and 35 at the end of 6 January. A balance can be added across products at one snapshot time, but 40 + 35 = 75 does not describe two-day stock. It is semi-additive across date.
Grain also controls discounts. If order O-90 has three lines and one order-level discount of 120, repeating 120 on every line reports 3 × 120 = 360. Either allocate the 120 to the lines with an explicit rule whose allocations sum to 120, or keep it in a separate order-grain fact.
Slowly changing dimensions preserve the historical city
Suppose customer C42 moves from Jaipur to Delhi. A Type 2 dimension closes the old version and inserts a new surrogate-key row:
Customer key | Customer ID | City | Effective from | Effective to | Current |
|---|---|---|---|---|---|
501 | C42 | Jaipur | 2025-08-01 | 2026-01-31 | N |
504 | C42 | Delhi | 2026-02-01 | open | Y |
OL-9001 and OL-9004 remain linked to key 501, so January sales still group under Jaipur. A separate line, OL-9010 dated 2026-02-03, links to key 504 and groups under Delhi. Because OL-9010 occurs in February, it sits outside the four January rows and the 5,050 reconciliation.
Type 1 would overwrite Jaipur with Delhi, simplifying the current profile but reclassifying January history. Type 2 is not mandatory for every attribute; the reporting history decides the change policy.

How exams test warehouse data modelling
Questions test the rules behind the model:
One order with three completed lines creates 3 fact rows at this grain.
Two orders containing 3 and 2 completed lines create 5 fact rows, not 2.
A category query uses one dimension join in the worked star and two in the snowflake.
Net sales can be summed across dates; end-of-day inventory balances cannot.
A Type 2 change needs a new surrogate-key row so old facts retain the old city.
Traps include selecting columns before declaring grain, mixing grains, treating every number as additive, joining on a non-unique business key, calling every denormalised model a star, and overwriting history. Before calculating, restate the grain, verify key uniqueness, and write the aggregation rule.
Practise by varying the grain, join path, measure type, and history policy. For placement-oriented revision across DBMS and other core subjects, use Computer Science Fundamentals for Placements by Sanchit Sir.
Data modelling in warehouses: the short version and next step
Use this order every time:
Write the business question.
Declare the fact grain.
Identify measures and their additivity.
Attach descriptive dimensions.
Choose durable surrogate keys.
Decide how history changes.
Reconcile test totals before loading more data.
The four facts must always reconcile to 8 units, gross sales 5,400, discount 350, and net sales 5,050. If a join changes those totals, test dimension-key uniqueness and fact grain before blaming the aggregate.
For broader CS fundamentals, ZERO TO HERO (Complete Course) is the structured next step. If you want to browse the wider catalogue instead, start with CS Fundamentals.
Keep learning
Data Modelling in Warehouses: 8 MCQs and 2 Descriptive Questions Solved
Solve ten published warehouse-modelling questions, then use the explanations to separate fact tables, star and snowflake schemas, fact constellations, cuboids and OLAP design.
Data Warehousing and Data Mining in DBMS: Star Schema, OLAP Operations and Apriori with Worked Examples
Move from warehouse vocabulary to hand-worked answers. Build a star schema, operate on a data cube, run Apriori, and follow two k-means iterations.
C++ enum class, struct, pair and tuple: How to Model Small Data Safely
Model Ticket 417 three ways, calculate the same response window, then add an owner to see why named fields often beat positional access in changing code.
Data Model, DBMS Architecture and Components: A Worked Query from Schema to Storage
Follow one university enrolment database from ER design to relations, views, heap pages and a B+ tree. Then trace a SQL query through the DBMS components.





