Type the fact table at the heart of the star — measures + one FK per dimension, composite PK.
Type the fact table at the heart of the star — measures + one FK per dimension, composite PK.
Answer
CREATE TABLE sales_fact ( date_key int REFERENCES dim_date, product_key int REFERENCES dim_product, store_key int REFERENCES dim_store, customer_key int REFERENCES dim_customer, units int, revenue numeric(10,2), PRIMARY KEY (date_key, product_key, store_key, customer_key) );
The fact table carries the numeric measures (units, revenue) and one foreign key to each dimension. Its primary key is the COMPOSITE of all those foreign keys — and that composite is exactly the grain: one row per (date, product, store, customer).