Data Modeling and Schema Design:• Designing a star schema
- Abhinandan Borse

- Sep 23, 2023
- 1 min read
Designing a star schema involves organizing data in a way that facilitates efficient querying and reporting. It's a popular schema for data warehousing, particularly for scenarios like e-commerce where there are distinct dimensions (e.g., products, customers, time) surrounding a central fact (e.g., sales).
In a star schema:
The fact table holds the quantitative data (e.g., sales amount).
Dimension tables store the descriptive attributes (e.g., product details, customer information).
Let's create a simplified star schema for an e-commerce database:
Fact Table: Sales(https://abhib854.wixsite.com/website/post/fact-and-dimension-table )
Columns:
order_id (Primary Key)
product_id (Foreign Key)
customer_id (Foreign Key)
order_date
quantity
total_price
Example data:

Dimension Table: Products(https://abhib854.wixsite.com/website/post/fact-and-dimension-table )
Columns:
product_id (Primary Key)
product_name
category
price
Example data:

Dimension Table: Customers
Columns:
customer_id (Primary Key)
first_name
last_name
email
Example data:

In this example:
The Sales table is the central fact table that contains information about each sale, such as the product sold, customer involved, and transaction details.
The Products table and Customers table are dimension tables. They contain details about products and customers, respectively.
The product_id and customer_id columns in the Sales table serve as foreign keys linking to the primary keys in the dimension tables.
This star schema allows for efficient queries about sales trends, customer behaviors, and product performance. It simplifies complex queries and provides a clear structure for reporting and analysis.
Comments