You are designing a database for a small retail store called Store 01. The store needs to track:
- Products in inventory
- Customers
- Orders placed by customers
- Items in each order
Design an Entity-Relationship Diagram (ERD) with the following entities and relationships:
| Table | Description |
|---|---|
products |
Product details: name, category, price, stock |
customers |
Customer details: name, email |
orders |
Orders placed by customers: order date, customer ID |
order_items |
Items in each order: product ID, quantity, price at time of purchase |
- A customer can place many orders
- An order can contain many products
- A product can be in many orders
- Design and draw the ERD including:
- Entity names
- Attributes (with PKs & FKs)
- Relationships between tables
Use MySQL to define the schema for the 4 core tables with:
- Primary Keys
- Foreign Keys
- Appropriate data types
Insert at least:
- 3 customers
- 5 products
- 15 orders (each with 2–3 items)
Write SQL to answer the following questions:
- List all orders with customer names and total amounts
- Find the most popular product by total quantity sold
- Show current stock left for each product
- List customers who haven’t placed any orders
-
Create roles/users:
store_manager: Full access to all tablessales_clerk: Can insert orders and view products, but cannot change product dataanalyst: Read-only access to all data
-
Grant privileges using
GRANT:store_manager:ALL PRIVILEGESon the whole databasesales_clerk:SELECTonproducts,INSERT/SELECTonordersandorder_itemsanalyst:SELECTonly on all tables
- Add a
categoriestable and link it toproducts(1 category → many products) - Create a trigger to reduce product stock when an
order_itemis added - Add
CHECKconstraints:- Price > 0
- Quantity ≥ 0
- SQL script to create and populate the database
- ERD diagram (image or draw.io URL)
- SQL query scripts for the tasks above
- README file (this one)
- Use
JOINstatements to connect related tables in your queries - Keep table and column names consistent and lowercase
- Add meaningful sample data to better test your queries
- MySQL
- ERD tool: dbdiagram.io, drawSQL, or draw.io
- Understand how to design normalized relational schemas
- Practice creating relationships with PKs and FKs
- Gain confidence writing SQL queries on realistic data