This project demonstrates the creation of a simple e-commerce database using MySQL.
It includes tables for customers, orders, and products, along with sample data and various SQL queries to perform common operations such as joins, aggregations, updates, and schema normalization.
ecommerce
Stores customer details.
| Column | Type | Description |
|---|---|---|
| id | INT (PK, AI) | Unique identifier for each customer |
| name | VARCHAR(100) | Customer name |
| VARCHAR(100) | Customer email (unique) | |
| address | VARCHAR(255) | Customer address |
Stores product information.
| Column | Type | Description |
|---|---|---|
| id | INT (PK, AI) | Unique identifier for each product |
| name | VARCHAR(100) | Product name |
| price | DECIMAL(10,2) | Product price |
| description | TEXT | Product description |
| discount | DECIMAL(5,2) | Discount on product (added later) |
Stores order details placed by customers.
| Column | Type | Description |
|---|---|---|
| id | INT (PK, AI) | Unique identifier for each order |
| customer_id | INT (FK) | References customers(id) |
| order_date | DATE | Date when the order was placed |
| total_amount | DECIMAL(10,2) | Total amount of the order |
The project includes sample records for:
- Multiple customers
- Several products (Product A, B, C, D)
- Orders with different dates and total amounts
Uses JOIN and date filtering with CURDATE().
Uses GROUP BY and SUM aggregation.
Updates the price of Product C to 45.00 using an UPDATE statement.
Adds a discount column to the products table using ALTER TABLE.
Orders products by price in descending order and limits results.
(Without normalization) assumes a product reference in orders; otherwise requires normalization.
Retrieves customer names along with their order dates.
Filters orders based on total_amount.
Introduces an order_items table to correctly map:
- Orders ↔ Products
- Supports multiple products per order
Calculates the average of all order totals using AVG().
Initially, the database contains only:
- customers
- orders
- products
To properly track which products belong to each order, the database is normalized by adding:
order_itemstable (order_id, product_id, quantity, price)
This follows best practices for relational database design.
- MySQL Server
- MySQL Workbench or any SQL client
- Create the database:
CREATE DATABASE ecommerce; USE ecommerce;