In this lesson, you will learn how to structure quantitative business events into "fact tables," which serve as the numerical heartbeat of your analytical data models.
What is a Fact Table?
When you move from an operational database (OLTP) to an analytical one (OLAP), you need to change how you store information. While your operational system might keep data in highly normalized tables to avoid redundancy, an analytical system needs to make it easy to perform math across millions of rows.
A fact table stores the "facts" of a business process—the measurable, quantitative events. Think of a transaction: the what happened, the when, and the how much.
Anatomy of a Fact Table
A well-designed fact table contains two primary components:
- Foreign Keys: These link the fact record to "dimension tables" (which describe the who, what, where of the event, like
customer_idorproduct_id). - Measures (Metrics): These are the numerical values that you intend to aggregate, such as
quantity_sold,discount_amount, ortax_rate.
Imagine you are running an online store. Instead of storing a complex customer profile in your sales record, you keep a lean table of events:
CREATE TABLE fact_sales (
sale_id INT, -- The specific event identifier
date_key INT, -- Foreign key to a Time Dimension
product_key INT, -- Foreign key to a Product Dimension
customer_key INT, -- Foreign key to a Customer Dimension
quantity_sold INT, -- Quantitative Metric
total_amount DECIMAL -- Quantitative Metric
);
Why Structure it This Way?
By keeping the fact table focused strictly on these keys and metrics, you achieve two things. First, you keep the table "narrow," meaning it consumes less storage and allows your columnar engines to scan metrics extremely quickly. Second, you make it simple for business intelligence tools to "slice and dice" the data. If a manager asks, "How many products were sold in Q3?", the analytical engine can filter the date_key and simply sum the quantity_sold column.
This separation of metrics from descriptive attributes is what allows analytical models to scale while maintaining high performance during complex aggregations.
Key Takeaway: Fact tables are the quantitative core of dimensional modeling, designed to store measurable business events linked to dimensions to facilitate fast, efficient aggregation.