This project solves the "Data Fragmentation" and "Overselling" problems faced by growing e-commerce businesses. I designed a normalized Relational Database to handle users, products, and orders, and built an automated Inventory Trigger System to ensure stock accuracy. Finally, I used Python to extract business insights and visualize revenue trends.
Figure 1: Project Overview Dashboard
| Revenue Growth | Top Categories |
|---|---|
![]() |
![]() |
| Identified seasonal sales spikes. | Clothing accounts for 40% of revenue. |
| Order Status | VIP Customers |
|---|---|
![]() |
![]() |
| 23% cancellation rate identified. | Top 5 customers by Lifetime Value. |
- Database: MySQL (Relational Schema, Foreign Keys)
- Backend Logic: Stored Procedures (ACID Transactions), Triggers
- Analytics: Python (Pandas, Matplotlib, Seaborn)
- Data Generation: Faker Library (Simulated 1,000+ records)
- Automated Stock Management:
AFTER INSERTtrigger automatically subtracts inventory when an order is placed.
- Safe Transactions:
place_orderStored Procedure usesCOMMIT/ROLLBACKto prevent financial errors during payment failures.
- Dynamic Dashboard:
- Jupyter Notebook connects directly to MySQL to render real-time charts.
The system follows 3rd Normal Form (3NF) to reduce redundancy:
Users1:NOrdersOrdersM:NProducts(viaOrder_Items)Orders1:1Payments
- Clone the Repo:
git clone https://github.com/sanaurrehmanarain/E_Commerce_SQL.git
- Install Dependencies:
pip install -r requirements.txt
- Setup Database:
- Open
schema.sqlin MySQL Workbench/VS Code and run it. - Run
triggers_transactions.sqlto set up the logic. - Run
generate_data.ipynbto populate the DB with realistic data.
- Open
- Launch Dashboard:
- Open
dashboard.ipynband run all cells to see the analytics.
- Open
Sana Ur Rehman Arain Data Analyst | SQL Expert | Python Developer



