Skip to content

Intermediate Project: An Online Store Database

Beginning of the lesson

Capstone: An Online Store Database

Design it, build it, protect it, and report on it — end to end

Big Idea: A real application database is not one clever query — it is a system. In this project you will model a small online store as four related tables, give it a normalized schema guarded by constraints, add the indexes its queries need, place orders safely inside a transaction, and answer business questions with CTEs and CASE. Every skill from topics 1-13 comes together here.
By the end you will be able to:
  • turn store requirements into entities and relationships and read an ER diagram,
  • write a normalized (3NF) schema whose CREATE TABLE statements enforce integrity with keys, NOT NULL, UNIQUE and CHECK,
  • choose indexes that match the store's real queries,
  • place an order atomically so stock and orders never drift apart,
  • build reports (top customers, revenue by product, monthly sales) with WITH and CASE.

1. The domain: entities and relationships

Start from the language of the business. A store has customers who place orders; each order contains one or more products, and for each product on an order we record how many were bought and the price at that moment. Those nouns become our tables:

EntityMeaningKey relationship
customerspeople who can buyone customer -> many orders
ordersa single purchase eventone order -> many order_items
productsthings for saleone product -> many order_items
order_itemsone product line on one orderlinks an order to a product

An order can hold many products, and a product can appear on many orders — a many-to-many relationship. We never join two tables directly across a many-to-many link; instead we introduce a junction (bridge) table, order_items, that holds one row per product-on-an-order plus the extra facts (quantity, unit price) that belong to that pairing.

customers PK customer_id email (UNIQUE) full_name created_at orders PK order_id FK customer_id order_date status order_items PK order_item_id FK order_id FK product_id quantity, unit_price products PK product_id name price stock 1 customer -> N orders 1 order -> N items 1 product -> N items
Two one-to-many links (customers-orders, products-order_items) resolve the customers/orders-to-products many-to-many through the order_items bridge.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers