What Is a Data Warehouse

A data warehouse is a large store of data collected from many sources and organised to support decision making, not day-to-day transactions. William Inmon described it by four properties:

  1. Subject-oriented: data is organised around subjects such as sales, customers or products, not around applications.
  2. Integrated: data from different sources is made consistent in names, units and formats.
  3. Time-variant: data is kept for a long period (often 5 to 10 years) so that trends can be studied, and every record is tied to a time.
  4. Non-volatile: once loaded, data is not updated or deleted; new data is only added.

Design Guidelines for Implementation

  • Decide the business process and the questions to be answered before building anything.
  • Choose the grain, the level of detail of one fact record (for example one line of a bill).
  • Identify the dimensions (who, what, where, when) and the facts (numbers to measure).
  • Use data from reliable source systems and plan the ETL (extract, transform, load) process.
  • Clean data and give every dimension record a simple surrogate key.
  • Plan storage, indexing and refresh frequency, and build in security and metadata.
  • Start with a small data mart for one department and grow, or build the whole enterprise warehouse in stages.

Dimensional Modelling

Dimensional modelling arranges data in a fact table surrounded by dimension tables. The fact table holds numeric measures (units sold, amount) and a foreign key to every dimension. A dimension table holds descriptive attributes (product name, category, city, month) and is used to filter and group.

Star and Snowflake Schema

  • Star schema: one central fact table linked directly to denormalised dimension tables. It is simple and fast because queries need few joins.
  • Snowflake schema: the dimension tables are normalised into several related tables, for example product linked to category. It saves space and avoids repeated data but needs more joins.
  • Fact constellation (galaxy): several fact tables share some dimension tables.

Definition: Fact table. The central table of a dimensional model that stores numeric measures of a business process and foreign keys to the dimension tables.

Table 1.1: Star schema compared with snowflake schema

Point Star schema Snowflake schema
Dimension tables Denormalised, one table each Normalised into sub-tables
Joins in a query Few More
Query speed Faster Slower
Storage More (repeated data) Less
Design Simple More complex

Example 1.1: Querying a star schema

Problem: A star schema has a fact table of 6 sales rows with amounts 100, 250, 600, 200, 300 and 200. The dimension product gives categories (Pen and Book are Stationery, Mouse is Electronics) and the dimension store gives cities. Find the total sales by category and by city.

Solution:

  1. Join the fact table to the product and store dimensions on their keys.
  2. Stationery rows (Pen 100, Book 250, Pen 200, Book 200): 100 + 250 + 200 + 200 = 750.
  3. Electronics rows (Mouse 600 and 300): 600 + 300 = 900.
  4. By city, Delhi has 100 + 250 + 300 = 650 and Pune has 600 + 200 + 200 = 1000.

Result: Stationery 750, Electronics 900, Delhi 650, Pune 1000; both ways of grouping total 1650.

import sqlite3
db = sqlite3.connect(":memory:")
db.executescript("""
CREATE TABLE product(pid, name, category);
CREATE TABLE store(sid, city);
CREATE TABLE sales(pid, sid, month, amount);
INSERT INTO product VALUES (1,'Pen','Stationery'),(2,'Book',
 'Stationery'),(3,'Mouse','Electronics');
INSERT INTO store VALUES (1,'Delhi'),(2,'Pune');
INSERT INTO sales VALUES (1,1,'Jan',100),(2,1,'Jan',250),
 (3,2,'Jan',600),(1,2,'Feb',200),(3,1,'Feb',300),(2,2,'Feb',200);
""")
q1 = """SELECT category, SUM(amount) FROM sales
        JOIN product USING(pid) GROUP BY category"""
q2 = """SELECT city, SUM(amount) FROM sales
        JOIN store USING(sid) GROUP BY city"""
print(db.execute(q1).fetchall())
print(db.execute(q2).fetchall())

Output

[('Electronics', 900), ('Stationery', 750)]
[('Delhi', 650), ('Pune', 1000)]

Common mistakes

  • Confusing a data warehouse with an operational database; it is built for analysis, not transactions.
  • Storing facts that cannot be added, or mixing different grains in one fact table.
  • Normalising every dimension and losing the speed of the star schema.
  • Starting to load data before the business questions are known.

Key takeaways

  • Data warehouse: subject-oriented, integrated, time-variant, non-volatile.
  • Fact table holds measures; dimension tables hold descriptions.
  • Star schema is denormalised and fast; snowflake is normalised and compact.
  • Decide the business process and grain first.

Practice questions

  1. Name the four properties of a data warehouse.
  2. What does a fact table store?
  3. How does a snowflake schema differ from a star schema?

Answers to the practice questions

  1. Subject-oriented, integrated, time-variant and non-volatile.
  2. Numeric measures and foreign keys to the dimension tables.
  3. Its dimension tables are normalised into sub-tables.

Sources

  • Official BCA syllabus Data Warehousing and Mining, course code 25BCA406DS03, Unit I