0% found this document useful (0 votes)
9 views7 pages

Triggers

The document outlines a project aimed at developing an online food delivery management system using PL/SQL, focusing on triggers and exception handling. It includes the design of schemas for restaurants, food items, and customer orders, as well as specific triggers to manage order confirmations, ratings, inventory updates, and notifications. Additionally, it addresses custom exception handling for invalid orders and ensures successful execution of the queries involved.

Uploaded by

Athish Vishnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Triggers

The document outlines a project aimed at developing an online food delivery management system using PL/SQL, focusing on triggers and exception handling. It includes the design of schemas for restaurants, food items, and customer orders, as well as specific triggers to manage order confirmations, ratings, inventory updates, and notifications. Additionally, it addresses custom exception handling for invalid orders and ensures successful execution of the queries involved.

Uploaded by

Athish Vishnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Ex.No.

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:

Restaurant (Restaurant_ID, Restaurant_name, Location, Rating)

Food Item (Item_number, Name, Restaurant_ID, Unit Price, Available quantity)

Customer Order (Customer_Order_ID, Customer_Name, Date, Address, Item_number,


Restaurant_ID, Quantity)

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);

create table notf (rname varchar(15), orat int, nrat int);


INSERTION OF RECORDS:

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.

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.

RESULT:
Thus, the above queries have been executed using exception and trigger concept using SQL successfully
verified and executed.

You might also like