Place an Order using Stored Procedure in SQL
Place an Order using Stored Procedure in SQL
A stored procedure in SQL is a set of precompiled SQL statements that can be executed as a
single unit. Stored procedures are stored in the database and can be invoked by applications
or users, allowing for greater modularity and reusability of code. Here are some key aspects:
Key Features:
Usage:
Dataset:
https://drive.google.com/drive/u/0/folders/1n6JT261WuEhRgfoEgQX2r2nYFVXm1DWu
1
2
Here are some examples of stored procedures based on the tables:
This stored procedure will insert a new order and its details into the order and order_details
tables.
3
new_order_id, input_user_id, input_r_id, input_amount, input_date, input_partner_id,
input_delivery_time, input_delivery_rating, input_restaurant_rating
);
4
IN input_order_id INT,
IN new_delivery_rating INT
BEGIN
UPDATE orders
END
------------------------------------------------------------------------------
5
3. Stored Procedure to Get Total Amount Spent by a User
This stored procedure calculates the total amount spent by a user based on their
user_id.
IN input_user_id INT,
BEGIN
FROM orders
END
----------------------------------------------------------------------------------
SELECT @total_spent;
6
4. Stored Procedure to Get All Orders with a Specific Partner
This procedure retrieves all orders that were delivered by a specific delivery partner based
on partner_id.
IN input_partner_id INT
BEGIN
SELECT *
FROM orders
END
-------------------------------------------------------------------------------------------
CALL GetOrdersByPartner(1);
This procedure retrieves all the details of a specific order, including the food items ordered.
7
IN input_order_id INT
BEGIN
FROM orders o
END
CALL GetOrderDetails(1001);