Dbms Final Report Mulinch
Dbms Final Report Mulinch
A
MICROPROJECT REPORT ON
Online Food Delivery
Submitted by: -
Roll Enrolment Name
number number
31 23210230250 Pradnya Mahadev Manakoji
95 23210230319 Jiya Jakir Tamboli
HOD PRINCIPAL
3
CONTENTS:
Sr No. CONTENTS
1. INTRODUCTION
2. ER DIAGRAM
3. NORMALIZATION :
4. FINAL TABLE:
5. CONSTRAINTS:
6. COMMANDS
TABLE
8. PL-SQL
9. Resources used
10. CONCLUSION
4
INTRODUCTION:
Literature Review:
Online food ordering systems have gained widespread popularity,
allowing customers to order food through websites or mobile apps,
offering convenience and efficiency. These systems typically include
features like menu browsing, order placement, and the choice of
delivery or pick-up. Research has focused on improving aspects like
user experience, payment security, and order tracking. Advances
include the use of AI for personalized recommendations and cloud-
based platforms for scalability and real-time order updates. Popular
platforms today allow customers to place orders through apps,
websites, or third-party services, improving accessibility.
5
ER MODELS FOR ENTITY:
6
7
ER MODEL FOR RELATIONSHIP:
8
NORMALIZATION TABLES:
9
Column Data Type Description
Name
food_id NUMBER(5) Primary Key
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
name VARCHAR2(100) Name of the food item (NOT NULL)
description VARCHAR2(50) Description of the food item
price DECIMAL(10,2) Price of the food item (NOT NULL)
category VARCHAR2(50) Category of the food item
• All columns contain atomic values, e.g., food_id, restaurant_id, name,
description, price, and category.
• There are no repeating groups in the table.
10
Column Data Type Description
Name
order_id NUMBER(10) Primary Key
customer_id NUMBER(5) Foreign Key (references
Customers.customer_id)
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
order_date DATE Date when the order was placed
status VARCHAR2(20) Status of the order (default: 'pending')
• All columns contain atomic values, e.g., order_id, customer_id,
restaurant_id, order_date, and status.
• There are no repeating groups or multi-valued attributes.
11
billing_id NUMBER(5) Primary Key
order_id NUMBER(5) Foreign Key (references
Orders.order_id)
billing_date DATE Date when the billing was created
payment_method VARCHAR2(50) Method of payment (e.g., Credit
Card, Cash, etc.)
• All columns contain atomic values, e.g., billing_id, order_id,
billing_date, and payment_method.
• There are no repeating groups or multi-valued attributes.
12
Column Data Type Description
Name
food_id NUMBER(5) Primary Key
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
name VARCHAR2(100) Name of the food item (NOT NULL)
description VARCHAR2(50) Description of the food item
price DECIMAL(10,2) Price of the food item (NOT NULL)
category VARCHAR2(50) Category of the food item
• All non-key attributes depend on the entire primary key (food_id), so
there are no partial dependencies.
13
Orders Table (2NF)
Column Data Type Description
Name
order_id NUMBER(10) Primary Key
customer_id NUMBER(5) Foreign Key (references
Customers.customer_id)
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
order_date DATE Date when the order was placed
status VARCHAR2(20) Status of the order (default: 'pending')
• All non-key attributes (customer_id, restaurant_id, order_date, status)
depend on the entire primary key (order_id), so there are no partial
dependencies.
14
Billing Table (2NF)
Column Name Data Type Description
billing_id NUMBER(5) Primary Key
order_id NUMBER(5) Foreign Key (references
Orders.order_id)
billing_date DATE Date when the billing was created
payment_method VARCHAR2(50) Method of payment (e.g., Credit
Card, Cash, etc.)
• All non-key attributes (order_id, billing_date, payment_method)
depend on the entire primary key (billing_id), so there are no partial
dependencies.
15
Food_Items Table (3NF)
Column Data Type Description
Name
food_id NUMBER(5) Primary Key
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
name VARCHAR2(100) Name of the food item (NOT NULL)
description VARCHAR2(50) Description of the food item
price DECIMAL(10,2) Price of the food item (NOT NULL)
category VARCHAR2(50) Category of the food item
• There are no transitive dependencies since all non-key attributes
depend directly on the primary key (food_id).
16
Orders Table (3NF)
Column Data Type Description
Name
order_id NUMBER(10) Primary Key
customer_id NUMBER(5) Foreign Key (references
Customers.customer_id)
restaurant_id NUMBER(5) Foreign Key (references
Restaurants.restaurant_id)
order_date DATE Date when the order was placed
status VARCHAR2(20) Status of the order (default: 'pending')
• There are no transitive dependencies since all non-key attributes
depend directly on the primary key (order_id).
17
Billing Table (3NF)
Column Name Data Type Description
billing_id NUMBER(5) Primary Key
order_id NUMBER(5) Foreign Key (references
Orders.order_id)
billing_date DATE Date when the billing was created
payment_method VARCHAR2(50) Method of payment (e.g., Credit
Card, Cash, etc.)
• There are no transitive dependencies since all non-key attributes
depend directly on the primary key (billing_id).
18
MICROPROJECT OUTPUT:
TABLE FOR RESTAURANT
19
TABLE FOR ORDERS
20
TABLE FOR BILLING
21
CONSTRAINTS
1. Restaurants
• Primary Key (PK): restaurant_id
• Not Null: name
2. Food_Items
• Primary Key (PK): food_id
• Foreign Key (FK): restaurant_id (References
Restaurants(restaurant_id))
• Not Null: name, price
3. Customers
• Primary Key (PK): customer_id
• Unique: email
• Not Null: name
4. Orders
• Primary Key (PK): order_id
• Foreign Key (FK): customer_id (References
Customers(customer_id)), restaurant_id (References
Restaurants(restaurant_id))
22
• Not Null: order_date, total_amount
• Default: status ('pending')
5. Order_Items
• Primary Key (PK): order_item_id
• Foreign Key (FK): order_id (References
Orders(order_id)), food_id (References
Food_Items(food_id))
• Not Null: quantity
6. Billing
• Primary Key (PK): billing_id
• Foreign Key (FK): order_id (References
Orders(order_id))
• Not Null: billing_date, payment_method, total_amount
23
MICROPROJECT CODE:
CREATE TABLE Restaurants(
restaurant_id number(5) PRIMARY KEY,
name VARCHAR2(100) NOT NULL,
location VARCHAR2(50),
contact VARCHAR2(20)
);
24
order_date DATE,
total_amount DECIMAL(10, 2),
status VARCHAR2(20) DEFAULT 'pending',
FOREIGN KEY (customer_id) REFERENCES Customers(customer_id),
FOREIGN KEY (restaurant_id) REFERENCES Restaurants(restaurant_id)
);
1. Insert Customers
INSERT ALL
INTO Customers (customer_id, name, email, phone, address) VALUES (11, 'Aarav Sharma',
'[email protected]', '91-9876543210', '101 A-Block, Connaught Place, New Delhi, 110001')
25
INTO Customers (customer_id, name, email, phone, address) VALUES (12, 'Vivaan Gupta',
'[email protected]', '91-8765432109', '202 B-Block, Marine Drive, Mumbai, 400020')
INTO Customers (customer_id, name, email, phone, address) VALUES (13, 'Aditya Patel',
'[email protected]', '91-7654321098', '303 C-Block, Indiranagar, Bangalore, 560038')
INTO Customers (customer_id, name, email, phone, address) VALUES (14, 'Kavya Reddy',
'[email protected]', '91-6543210987', '404 D-Block, Banjara Hills, Hyderabad, 500034')
INTO Customers (customer_id, name, email, phone, address) VALUES (15, 'Ananya Singh',
'[email protected]', '91-5432109876', '505 E-Block, Anna Nagar, Chennai, 600040')
INTO Customers (customer_id, name, email, phone, address) VALUES (16, 'Rohan Mehta',
'[email protected]', '91-4321098765', '606 F-Block, Shivajinagar, Pune, 411005')
INTO Customers (customer_id, name, email, phone, address) VALUES (17, 'Sneha Iyer',
'[email protected]', '91-3210987654', '707 G-Block, Salt Lake, Kolkata, 700091')
INTO Customers (customer_id, name, email, phone, address) VALUES (18, 'Arjun Verma',
'[email protected]', '91-2109876543', '808 H-Block, Bais Godam, Jaipur, 302006')
INTO Customers (customer_id, name, email, phone, address) VALUES (19, 'Pooja Joshi',
'[email protected]', '91-1098765432', '909 I-Block, Navrangpura, Ahmedabad, 380009')
INTO Customers (customer_id, name, email, phone, address) VALUES (20, 'Rajesh Bhatia',
'[email protected]', '91-0987654321', '100 J-Block, Adajan, Surat, 395009')
SELECT * FROM dual;
2. Insert Restaurants
INSERT ALL
INTO Restaurants (restaurant_id, name, location, contact) VALUES (1, 'Biryani Paradise',
'Paharganj, New Delhi', '91-9876543210')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (2, 'Tandoori Nights',
'Sector 17, Chandigarh', '91-8765432109')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (3, 'Curry House',
'Jayanagar, Bangalore', '91-7654321098')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (4, 'Spice Route',
'Connaught Place, New Delhi', '91-6543210987')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (5, 'Punjabi Tadka', 'Hauz
Khas, New Delhi', '91-5432109876')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (6, 'Saffron Spice',
'Colaba, Mumbai', '91-4321098765')
26
INTO Restaurants (restaurant_id, name, location, contact) VALUES (7, 'Dosa King',
'Koramangala, Bangalore', '91-3210987654')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (8, 'Rasam Ruchi',
'Madhapur, Hyderabad', '91-2109876543')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (9, 'Gulab Jamun Corner',
'Malleswaram, Bangalore', '91-1098765432')
INTO Restaurants (restaurant_id, name, location, contact) VALUES (10, 'Chaat Street',
'Andheri, Mumbai', '91-0987654321')
SELECT * FROM dual;
27
INTO Food_Items (food_id, restaurant_id, name, description, price, category) VALUES (13,
7, 'Grilled Fish', 'Fish fillet marinated and grilled to perfection', 299.00, 'Main Course')
INTO Food_Items (food_id, restaurant_id, name, description, price, category) VALUES (14,
7, 'Samosa', 'Crispy pastry filled with spiced potatoes', 99.00, 'Appetizer')
INTO Food_Items (food_id, restaurant_id, name, description, price, category) VALUES (15,
8, 'Pasta Primavera', 'Pasta with seasonal vegetables in a light sauce', 199.00, 'Main Course')
INTO Food_Items (food_id, restaurant_id, name, description, price, category) VALUES (16,
8, 'Aloo Tikki', 'Spiced potato patties served with chutney', 99.00, 'Appetizer')
SELECT * FROM dual;
4. Insert Orders
INSERT ALL
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (1, 11, 1,
598.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (2, 12, 2,
299.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (3, 11, 3,
499.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (4, 12, 4,
249.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (5, 13, 5,
399.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (6, 14, 6,
199.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (7, 15, 7,
499.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (8, 16, 8,
399.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (9, 17, 1,
250.00, 'pending')
INTO Orders (order_id, customer_id, restaurant_id, total_amount, status) VALUES (10, 18, 2,
599.00, 'pending')
SELECT * FROM dual;
28
5. Insert Order Items
INSERT ALL
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (1, 1, 2, 398.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (1, 2, 1, 149.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (2, 3, 1, 249.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (2, 4, 1, 99.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (3, 5, 1, 299.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (3, 6, 1, 199.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (4, 7, 1, 199.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (4, 8, 1, 149.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (5, 9, 1, 299.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (5, 10, 1, 99.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (6, 11, 1, 149.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (6, 12, 1, 199.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (7, 13, 1, 299.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (7, 14, 1, 99.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (8, 15, 1, 199.00)
INTO Order_Items (order_id, food_id, quantity, subtotal) VALUES (8, 16, 1, 99.00)
SELECT * FROM dual;
6. Insert Billing
INSERT ALL
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (1,
1, CURRENT_TIMESTAMP, 'Credit Card', 598.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (2,
2, CURRENT_TIMESTAMP, 'Cash', 299.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (3,
3, CURRENT_TIMESTAMP, 'Debit Card', 499.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (4,
4, CURRENT_TIMESTAMP, 'UPI', 249.00)
29
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (5,
5, CURRENT_TIMESTAMP, 'Credit Card', 399.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (6,
6, CURRENT_TIMESTAMP, 'Cash', 199.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (7,
7, CURRENT_TIMESTAMP, 'Debit Card', 499.00)
INTO Billing (billing_id, order_id, billing_date, payment_method, total_amount) VALUES (8,
8, CURRENT_TIMESTAMP, 'Cash', 399.00)
SELECT * FROM dual;
DECLARE
v_order_id INT := 1; -- Set this to the order you want to check
v_payment_count INT;
BEGIN
-- Check if the payment has been made for the given order_id
SELECT COUNT(*) INTO v_payment_count
FROM Billing
WHERE order_id = v_order_id;
30
DBMS_OUTPUT.PUT_LINE('Please pay your bill.');
END IF;
END;
/
DECLARE
v_order_id Orders.order_id%TYPE;
v_customer_name Customers.name%TYPE;
v_restaurant_name Restaurants.name%TYPE;
v_order_date Orders.order_date%TYPE;
v_food_id Food_Items.food_id%TYPE;
v_food_name Food_Items.name%TYPE;
v_quantity Order_Items.quantity%TYPE;
v_subtotal Order_Items.subtotal%TYPE;
v_order_total Orders.total_amount%TYPE;
v_billing_date Billing.billing_date%TYPE;
v_payment_method Billing.payment_method%TYPE;
v_billing_total Billing.total_amount%TYPE;
v_status Orders.status%TYPE;
BEGIN
v_order_id := 1;
v_customer_name := 'John Doe';
v_restaurant_name := 'Pasta Place';
v_order_date := SYSDATE;
v_food_id := 101;
v_food_name := 'Spaghetti';
v_quantity := 2;
v_subtotal := 20.00;
v_order_total := 50.00;
31
v_billing_date := SYSDATE;
v_payment_method := 'Credit Card';
v_billing_total := 50.00;
v_status := 'Completed';
DBMS_OUTPUT.PUT_LINE('-----------------------------------');
DBMS_OUTPUT.PUT_LINE('Order ID: ' || v_order_id);
DBMS_OUTPUT.PUT_LINE('Customer: ' || v_customer_name);
DBMS_OUTPUT.PUT_LINE('Restaurant: ' || v_restaurant_name);
DBMS_OUTPUT.PUT_LINE('Order Date: ' || v_order_date);
DBMS_OUTPUT.PUT_LINE('Food Item: ' || v_food_name);
DBMS_OUTPUT.PUT_LINE('Quantity: ' || v_quantity);
DBMS_OUTPUT.PUT_LINE('Subtotal: ' || v_subtotal);
DBMS_OUTPUT.PUT_LINE('Order Total: ' || v_order_total);
DBMS_OUTPUT.PUT_LINE('Billing Date: ' || v_billing_date);
DBMS_OUTPUT.PUT_LINE('Payment Method: ' || v_payment_method);
DBMS_OUTPUT.PUT_LINE('Billing Total: ' || v_billing_total);
DBMS_OUTPUT.PUT_LINE('Status: ' || v_status);
DBMS_OUTPUT.PUT_LINE('-----------------------------------');
END;
32
SQL COMMANDS FOR DML OPERATIONS ON TABLE
• INSERT Statement:
INSERT INTO Restaurants (restaurant_id, name, location,
contact)
VALUES (1, 'Pizza Place', '123 Main St', '555-1234');
• UPDATE Statement:
UPDATE Customers
SET phone = '555-9999'
WHERE customer_id = 1;
• DELETE Statement:
DELETE FROM Orders
WHERE order_id = 1;
33
• Using GROUP BY Clause:
SELECT restaurant_id, COUNT(*)
FROM Food_Items
GROUP BY restaurant_id;
• Using HAVING Clause:
SELECT restaurant_id, COUNT(*)
FROM Food_Items
GROUP BY restaurant_id
HAVING COUNT(*) > 2;
• Subquery Example (Using IN):
SELECT name
FROM Restaurants
WHERE restaurant_id IN (SELECT restaurant_id
FROM Orders
WHERE total_amount > 50);
• Using JOIN (Equi-Join):
SELECT c.name AS customer_name, o.order_id
FROM Customers c
JOIN Orders o ON c.customer_id = o.customer_id;
• Set Operators - UNION:
SELECT name FROM Customers
UNION
SELECT name FROM Restaurants;
34
SQL COMMANDS FOR PL-SQL OPERATIONS ON
TABLE
1. PL/SQL Procedure:
Create a Procedure to Add a New Order:
CREATE PROCEDURE Add_New_Order(p_customer_id
NUMBER(9), p_restaurant_id NUMBER(9), p_total_amount
NUMBER(9)) AS
BEGIN
INSERT INTO Orders (customer_id, restaurant_id,
total_amount)
VALUES (p_customer_id, p_restaurant_id, p_total_amount);
COMMIT;
END;
Calling Add_New_Order Procedure:
BEGIN
Add_New_Order(p_customer_id => 1001, p_restaurant_id =>
200, p_total_amount => 1500);
END;
Output:
SELECT * FROM Orders WHERE customer_id = 101;
Sample Output:
ORDER_ID | CUSTOMER_ID | RESTAURANT_ID TOTAL_AMOUNT ORDER_DATE
35
CREATE PROCEDURE Update_Food_Item_Price(p_food_id
NUMBER(9), p_new_price NUMBER(9)) AS
BEGIN
UPDATE Food_Items
SET price = p_new_price
WHERE food_id = p_food_id;
COMMIT;
END;
• Calling the Procedure to Update Food Item Price
Procedure Code:
BEGIN
Update_Food_Item_Price(p_food_id => 101, p_new_price =>
250);
END;
Output:
SELECT food_id, price FROM Food_Items WHERE food_id =
101;
Sample Output:
FOOD_ID | PRICE
101 | 799
2. PL/SQL Function:
1.Create a Function to Get the Price of a Food Item:
CREATE FUNCTION Get_Food_Item_Price(p_food_id
NUMBER(9)) RETURN NUMBER AS
v_price NUMBER(9);
BEGIN
36
SELECT price INTO v_price
FROM Food_Items
WHERE food_id = p_food_id;
RETURN v_price;
END;
Sample Output:
GET_FOOD_ITEM_PRICE(101)
799
500
37
3. PL/SQL Trigger:
1.Create a Trigger Before Inserting a Food Item to
Validate Price:
4. PL/SQL Sequence:
1.Create a Sequence for Generating Restaurant IDs:
CREATE SEQUENCE restaurant_seq
START WITH 1
INCREMENT BY 1;
38
Using Sequence to Generate Restaurant ID
Sample Output (Assuming this is the first insert):
RESTAURANT_ID | NAME | LOCATION | CONTACT
5. PL/SQL Exception:
1.Use Built-in Exception (e.g., Handling No Data Found):
BEGIN
SELECT *
FROM Food_Items
WHERE food_id = -1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No food item found.');
END;
Handling Built-in Exception (No Data Found)
Output:
No food item found.
40
Resources used
1.W3Schools
▪ SQL Tutorial: Offers interactive lessons on SQL with examples
and quizzes. A great resource for beginners.
• W3Schools SQL Tutorial
▪ PL/SQL Tutorial: While primarily focused on SQL, W3Schools
provides basic PL/SQL examples and explanations, which are
helpful for getting started.
• W3Schools PL/SQL Tutorial
2.Documentation & Official Resources:
• Oracle PL/SQL Documentation: Oracle Docs
• MySQL Docs: MySQL Documentation
• PostgreSQL Docs: PostgreSQL Documentation
41
❖ Simple Queries
❖ WHERE Clause
42
SELECT *
FROM Food_Items
WHERE price > 0;
2.List customers who live in New York:
SELECT *
FROM Customers
WHERE address LIKE '%New York%';
3.List all orders placed after January 1, 2024:
SELECT *
FROM Orders
WHERE order_date > TO_DATE('2024-01-01', 'YYYY-MM-
DD');
4.List food items that are priced under ₹750:
SELECT *
FROM Food_Items
WHERE price < 750;
5.List customers who have placed orders in the last month:
SELECT DISTINCT c.*
FROM Customers c
JOIN Orders o ON c.customer_id = o.customer_id
WHERE o.order_date > ADD_MONTHS(SYSDATE, -1);
6.List all orders with a total bill greater than ₹4,000:
SELECT *
FROM Orders
WHERE total_amount > 4000;
43
❖ ORDER BY Clause
1.List customer names in ascending order:
SELECT name
FROM Customers
ORDER BY name ASC;
2.List all food items ordered by price in descending order:
SELECT *
FROM Food_Items
ORDER BY price DESC;
3.List orders sorted by order date from latest to oldest:
SELECT *
FROM Orders
ORDER BY order_date DESC;
4.List billing records sorted by billing date:
SELECT *
FROM Billing
ORDER BY billing_date;
5.List customers sorted by registration date: Assuming
registration date is the first order date, or you have a column for
registration:
SELECT *
FROM Customers
ORDER BY customer_id;
6.List food items sorted by name in ascending order:
SELECT *
FROM Food_Items
ORDER BY name ASC;
❖ GROUP BY Clause
44
1.List the number of orders placed by each customer:
SELECT customer_id, COUNT(*) AS num_orders
FROM Orders
GROUP BY customer_id;
2.List the total sales amount for each food item:
SELECT fi.food_id, fi.name, SUM(oi.quantity * oi.subtotal) AS
total_sales
FROM Food_Items fi
JOIN Order_Items oi ON fi.food_id = oi.food_id
GROUP BY fi.food_id, fi.name;
3.List the average bill amount for each customer:
SELECT customer_id, AVG(total_amount) AS avg_bill
FROM Orders
GROUP BY customer_id;
4.List the number of food items ordered in each order:
SELECT order_id, SUM(quantity) AS total_items_ordered
FROM Order_Items
GROUP BY order_id;
5.List the total number of food items grouped by category:
SELECT category, SUM(quantity) AS total_items
FROM Order_Items oi
JOIN Food_Items fi ON oi.food_id = fi.food_id
GROUP BY category;
❖ HAVING Clause
1.List customers with more than 5 orders:
SELECT customer_id, COUNT(*) AS num_orders
FROM Orders
GROUP BY customer_id
45
HAVING COUNT(*) > 5;
2.List food items with total sales greater than ₹80,000:
SELECT fi.food_id, fi.name, SUM(oi.quantity * oi.subtotal) AS
total_sales
FROM Food_Items fi
JOIN Order_Items oi ON fi.food_id = oi.food_id
GROUP BY fi.food_id, fi.name
HAVING SUM(oi.quantity * oi.subtotal) > 80000;
3.List categories where the average price exceeds ₹1,500:
SELECT category, AVG(price) AS avg_price
FROM Food_Items
GROUP BY category
HAVING AVG(price) > 1500;
4.List orders with a total bill greater than ₹15,000:
SELECT * FROM Orders
HAVING total_amount > 15000;
5.List cities with more than 50 customers:
SELECT SUBSTRING(address, INSTR(address, ',') + 1) AS
city, COUNT(*) AS num_customers
FROM Customers
GROUP BY SUBSTRING(address, INSTR(address, ',') + 1)
HAVING COUNT(*) > 50;
6.List food categories where the total quantity sold is greater
than 100:
SELECT fi.category, SUM(oi.quantity) AS total_quantity
FROM Order_Items oi
JOIN Food_Items fi ON oi.food_id = fi.food_id
GROUP BY fi.category
HAVING SUM(oi.quantity) > 100;
46
❖ JOINS
1.List all orders along with customer names:
SELECT o.order_id, c.name AS customer_name,
o.total_amount
FROM Orders o
JOIN Customers c ON o.customer_id = c.customer_id;
2.List all order items with corresponding food item names:
SELECT oi.order_item_id, fi.name AS food_item, oi.quantity,
oi.subtotal
FROM Order_Items oi
JOIN Food_Items fi ON oi.food_id = fi.food_id;
3.List billing records along with order details:
SELECT b.billing_id, o.order_id, b.billing_date,
b.payment_method, b.total_amount
FROM Billing b
JOIN Orders o ON b.order_id = o.order_id;
4.List customers with their order details:
SELECT c.name AS customer_name, o.order_id,
o.total_amount
FROM Customers c
JOIN Orders o ON c.customer_id = o.customer_id;
5.List food items and their categories:
SELECT fi.name AS food_item, fi.category
FROM Food_Items fi;
6.List suppliers and the food items they supply:
(Assuming there is a "Suppliers" table linked with
"Food_Items".)
SELECT s.supplier_name, fi.name AS food_item
FROM Suppliers s
JOIN Food_Items fi ON s.supplier_id = fi.supplier_id;
47
❖ Set Operations
1.List all food items that are available and all discontinued food
items:
SELECT name
FROM Food_Items
WHERE status = 'Available'
UNION
SELECT name
FROM Food_Items
WHERE status = 'Discontinued';
2.List all customers who have placed orders combined with
those who have not:
SELECT customer_id
FROM Orders
UNION
SELECT customer_id
FROM Customers;
2.List all customer IDs in orders and billing records:
SELECT customer_id
FROM Orders
UNION
SELECT customer_id
FROM Billing;
3.List all unique food item names from current food items and
seasonal specials:
SELECT name
FROM Food_Items
WHERE status = 'Current'
UNION
SELECT name
48
FROM Food_Items
WHERE status = 'Seasonal';
4.List all customer emails from the current customer table and
the archived customer table:
SELECT email
FROM Customers
UNION
SELECT email
FROM Archived_Customers;
5.List all food item IDs from vegetarian and non-vegetarian
categories:
SELECT food_id
FROM Food_Items
WHERE category = 'Vegetarian'
UNION
SELECT food_id FROM Food_Items
WHERE category = 'Non-Vegetarian';
❖ Subqueries
1.List all customers who have placed orders with total amounts
greater than the average order amount:
SELECT * FROM Customers c
WHERE c.customer_id IN (
SELECT o.customer_id
FROM Orders o
WHERE o.total_amount > (SELECT AVG(total_amount)
FROM Orders));
2.List all food items that are priced above the average price in
their category:
49
SELECT * FROM Food_Items fi
WHERE fi.price > (
SELECT AVG(price)
FROM Food_Items
WHERE category = fi.category);
3.List orders placed by customers from California:
SELECT * FROM Orders o
WHERE o.customer_id IN (
SELECT c.customer_id
FROM Customers c
WHERE c.address LIKE '%California%');
4.List customers who have ordered food items from a specific
category:
SELECT DISTINCT c.*
FROM Customers c
JOIN Orders o ON c.customer_id = o.customer_id
JOIN Order_Items oi ON o.order_id = oi.order_id
JOIN Food_Items fi ON oi.food_id = fi.food_id
WHERE fi.category = 'Pizza';
5.List all food items that have been ordered more than the
average quantity:
SELECT fi.name, SUM(oi.quantity) AS total_quantity
FROM Food_Items fi
JOIN Order_Items oi ON fi.food_id = oi.food_id
GROUP BY fi.food_id, fi.name
HAVING SUM(oi.quantity) > (SELECT AVG(quantity)
FROM Order_Items);
6.List all customers who have made orders greater than
₹40,000:
SELECT c.*
FROM Customers c
50
WHERE c.customer_id IN (
SELECT o.customer_id
FROM Orders o
WHERE o.total_amount > 40000
);
51
Conclusion
The Restaurant Management System is a web-based
platform designed to streamline restaurant operations such as
order management, billing, employee scheduling, and
inventory control. By automating these processes, the system
helps restaurant managers make data-driven decisions and
optimize resources efficiently. The system also ensures
secure data handling and provides a user-friendly experience
for both staff and customers, making it an effective
replacement for traditional manual methods.
Learning Outcomes:
▪ We learned how to Design the database for a
restaurant management system by using an Entity-
Relationship (ER) diagram and normalizing it to 1NF,
2NF, and 3NF.
▪ We learned the concept of Database Management
Systems (DBMS), including its types, components, and
the role of DBMS in managing large datasets and
ensuring data integrity, security, and consistency.
▪ We understood how to Manage the database using
SQL by performing various operations like creating
tables, inserting data, and using queries to retrieve and
update information efficiently.
▪ We learned how to Implement PL/SQL code for the
restaurant application, including logic for handling
order processing, billing, and payment status updates,
52
demonstrating the ability to write stored procedures,
triggers, and functions.
▪ Applied security and backup methods on the
database to ensure that sensitive data is protected, users
have appropriate access levels, and the database is
regularly backed up for disaster recovery.
Applications:
1. Restaurant Operations: Automates daily tasks like
order taking and billing.
2. Customer Relationship Management (CRM):
Enhances customer service with personalized data.
3. Data Analytics: Helps managers make informed
decisions through reports and insights.
4. Third-Party Integrations: Supports integration with
payment and delivery systems.
5. Security: Ensures secure handling of sensitive data.
Reference:
www.google.com
www.chrome.com
www.food.com
www.zomato.com
53
54