Triggers
Triggers
9
ONLINE FOOD DELIVERY MANAGEMENT USING TRIGGERS AND
EXCEPTION HANDLING MECHANISMS IN PL/SQL
25.03.25
AIM:
To Use PL/SQL, design triggers and handle exceptions for an online food delivery company. You can use
the following schemas:
Insert at least 5 records in the necessary tables and hence write queries to process the following:
1. Create a trigger that checks if the delivery address is within the restaurant’s service area
before confirming the order.
2. Design a trigger that updates the restaurant's rating based on the average rating of its food items.
3. Raise a trigger to automatically update the quantity available for an item after each
customer order.
4. Design a trigger to send a notification (store in a Notifications table) whenever a
restaurant’s rating drops below 3.
5. Develop a block to handle custom exceptions like "Item_NotFound_Exception" if a customer
tries to order an item unavailable in a given restaurant or with invalid restaurant ID.
6. Handle the exception when a customer tries to place an order with a negative or zero quantity.
SCHEMAS:
RESTAURANT:
FOOD_ITEM:
CUSTOMER_ORDER:
CREATION OF TABLES:
create table restaurant (rid int primary key, rname varchar(15) unique, loc varchar(15), rat int);
create table f_item (itno int primary key, name varchar(15) unique, rid int, upr int not null, quan int, rat
int, foreign key (rid) references restaurant(rid) on delete cascade);
create table corder (cid int primary key, cname varchar(15) unique, cdate date, addr varchar(15), itno int,
rid int, qua int, foreign key (itno) references f_item(itno) on delete cascade, foreign key (rid) references
restaurant(rid) on delete cascade);
RESTAURANT:
insert into restaurant values (1, 'Lsg', 'Singanallur', 4);
insert into restaurant values (2, 'srh', 'Singanallur', 3);
insert into restaurant values (3, 'Cskfood', 'gvresi', 3);
insert into restaurant values (4, 'irfo', 'esi', 5);
insert into restaurant values (5, 'svr', 'sulur', 4);
FOOD_ITEM:
insert into f_item values(10, 'Pasta', 1, 234, 30, 5);
insert into f_item values(11, 'Pizza', 1, 195, 25, 5);
insert into f_item values(12, 'Burger', 1, 150, 40, 2);
insert into f_item values(13, 'Chips', 3, 86, 50, 4);
insert into f_item values(14, 'ColdCoffee', 5, 216, 18, 5);
CUSTOMER_ORDER:
insert into corder values(1, 'Alice', to_date('15-mar-2025', 'dd-mon-yyyy'), 'Singanallur', 10, 1, 15);
insert into corder values(2, 'Bob', to_date('16-mar-2025', 'dd-mon-yyyy'), 'Perur', 11, 1, 10);
insert into corder values(3, 'Charlie', to_date('17-mar-2025', 'dd-mon-yyyy'), 'Singanallur', 10, 1, 10);
insert into corder values(4, 'David', to_date('18-mar-2025', 'dd-mon-yyyy'), 'Singanallur', 12, 1, 5);
insert into corder values(5, 'Eve', to_date('19-mar-2025', 'dd-mon-yyyy'), 'Sulur', 14, 5, -5);
RECORDS:
RESTAURANT:
FOOD_ITEM:
CUSTOMER_ORDER:
QUERIES:
1.Create a trigger that checks if the delivery address is within the restaurant’s service area before
confirming the order.
2.Design a trigger that updates the restaurant's rating based on the average rating of its food items.
3. Raise a trigger to automatically update the quantity available for an item after each customer order.
4. Design a trigger to send a notification (store in a Notifications table) whenever a restaurant’s
rating drops below 3.
RESULT:
Thus, the above queries have been executed using exception and trigger concept using SQL successfully
verified and executed.