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:
customersordersproducts
- Normalize the database by adding an
order_itemstable. - 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.idorder_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
productstable - Retrieve the top 3 products with the highest price
- Get the names of customers who have ordered "Product A"
- Join
ordersandcustomersto get customer name and order date - Retrieve orders with total amount greater than 150.00
- Normalize database with a new
order_itemstable - 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
ordersandproducts. - Contains:
id,order_id,product_id,quantity.
Customers βββ< Orders βββ< Order_Items >βββ βββ Products
- Developed by: Vignesh R
- GitHub: @VigneshRav
- Email: vignesh212000@gmail.com
