This project sets up a basic e-commerce database system using MySQL. It includes three primary tables—customers
, orders
, and products
—with normalized extensions and a set of queries for data retrieval and manipulation.
- Create a database named
ecommerce
. - Design and implement three core tables:
customers
orders
products
- Normalize the database by adding an
order_items
table. - Insert sample data into all tables.
- Write essential SQL queries to interact with the data.
ecommerce
id
(INT, PK, AUTO_INCREMENT): Unique customer IDname
(VARCHAR): Customer's nameemail
(VARCHAR): Customer's emailaddress
(VARCHAR): Customer's address
id
(INT, PK, AUTO_INCREMENT): Unique order IDcustomer_id
(INT, FK): Referencescustomers.id
order_date
(DATE): Date of the ordertotal_amount
(DECIMAL): Total order value
id
(INT, PK, AUTO_INCREMENT): Unique product IDname
(VARCHAR): Product nameprice
(DECIMAL): Product pricedescription
(TEXT): Product description
Sample entries are inserted into all three tables to demonstrate database functionality and facilitate query testing.
- Retrieve all customers who have placed an order in the last 30 days
- Get total amount of all orders placed by each customer
- Update the price of "Product C" to 45.00
- Add a discount column to the
products
table - Retrieve the top 3 products with the highest price
- Get the names of customers who have ordered "Product A"
- Join
orders
andcustomers
to get customer name and order date - Retrieve orders with total amount greater than 150.00
- Normalize database with a new
order_items
table - Retrieve the average total of all orders
All queries use MySQL syntax and include clear comments for documentation.
A new table order_items
is created to normalize the schema:
- Supports many-to-many relationships between
orders
andproducts
. - Contains:
id
,order_id
,product_id
,quantity
.
Customers └──< Orders └──< Order_Items >──┐ └── Products
- Developed by: Vignesh R
- GitHub: @VigneshRav
- Email: vignesh212000@gmail.com