Online Shopping (E-Commerce) Database System
1. Problem Statement
An Online Shopping System wants to design a database to manage
customers, products, orders, order items, payments, and delivery.
A customer can place multiple orders.
Each order can contain multiple products.
Each product can appear in many orders.
Payments are recorded for orders, and delivery details are maintained.
The system must generate reports such as total sales, customer purchase
history, best-selling products, and pending deliveries.
Constraints:
Customer places Order (1 : M)
Order contains Products (M : N via OrderItem)
Order has Payment (1 : 1)
Order has Delivery (1 : 1)
Price > 0
Quantity ≥ 1
Stock ≥ 0
Payment Amount ≥ 0
DDL QUERY QUESTIONS (10)
Q1. Create a table CUSTOMER with appropriate attributes.
Q2. Create a table PRODUCT with price and stock information.
Q3. Create ORDERS table with foreign key reference to CUSTOMER.
Q4. Create ORDERITEM table to resolve many-to-many relationship.
Q5. Create PAYMENT table linked with ORDERS.
Q6. Create DELIVERY table for order delivery tracking.
Q7. Add a new column Brand to PRODUCT table.
Q8. Modify Phone field size in CUSTOMER table.
Q9. Add ShippingCharge column to ORDERS table.
Q10. Drop DELIVERY table.
DML QUERY QUESTIONS (10)
Q1. Insert two customer records.
Q2. Insert two products into PRODUCT table.
Q3. Insert an order placed by a customer.
Q4. Insert items for an order.
Q5. Insert payment details for an order.
Q6. Update product stock after purchase.
Q7. Update order status to ‘Shipped’.
Q8. Delete an order item.
Q9. Update customer address.
Q10. Delete a customer record.
C. CONSTRAINTS & KEYS QUESTIONS (10)
Q1. Add UNIQUE constraint on customer email.
Q2. Ensure product price is greater than zero.
Q3. Ensure stock cannot be negative.
Q4. Ensure order quantity is at least 1.
Q5. Ensure payment amount is non-negative.
Q6. Restrict order status values.
Q7. Make ProductName NOT NULL.
Q8. Make Customer Name NOT NULL.
Q9. Make PaymentMode mandatory.
Q10. Add foreign key constraint on Orders.
D. JOINS & SUBQUERIES QUESTIONS (15)
Q1. Display customer names with their order IDs.
Q2. List products that have been ordered.
Q3. Find customers who never placed an order.
Q4. Display order ID with payment amount.
Q5. List products not ordered yet.
Q6. Display total orders per customer.
Q7. Display total payment collected.
Q8. Show orders with customer name.
Q9. Find products priced above average.
Q10. Display all unique product categories.
Q11. Find orders that have payments.
Q12. Find customers with placed orders.
Q13. Display products with order quantity.
Q14. Count products in each order.
Q15. Find customers who have placed at least one order.
E. AGGREGATE & GROUP BY QUESTIONS (10)
Q1. Count total customers.
Q2. Count total orders.
Q3. Find total revenue.
Q4. Find average product price.
Q5. Find maximum product price.
Q6. Find minimum product price.
Q7. Count products by category.
Q8. Count orders per customer.
Q9. Count orders by status.
Q10. Find total quantity sold per product.
F. VIEWS / INDEX QUESTIONS (5)
Q1. Create a view showing customer orders.
Q2. Display the view.
Q3. Create index on product name.
Q4. Create index on order date.
Q5. Drop the view.
PLSQL UNNAMED BLOCK AND CURSORS:
1. Write a PL/SQL program to display customer name and email for a
given Customer ID
2. Write a PL/SQL program to Update Product Stock after Purchase
with a message as “Update Successfully”.
3. Write a PL/SQL program using cursor to display order ID and
customer name.
PLSQL NAMED BLOCK:
1. Procedure to Insert New Customer
2. Function to Calculate Order Total
TRIGGER:
1. Trigger to Prevent Negative Stock
2. Trigger to Auto-Insert Payment Record