Create Procedure
Create Procedure
Directions for Lab Exercise: Converting Tables to Queries on your paper. (Individual work)(50 points)a
Objective:
You are managing a database for an e-commerce company that sells products online. The database has the following two tables:
Exercise Questions
Scenario:
Scenario:
You are managing a database for an e-commerce company that sells products online. The database has the following two tables:
1. Customers
● customer_id (Primary Key)
● first_name
● last_name
● email
● phone_number
● address
2. Orders
● order_id (Primary Key)
● customer_id (Foreign Key)
● order_date
● order_amount
● status (Pending, Completed, Canceled)
Tasks:
Question: Create a stored procedure to select all customer records from the Customers table. Ensure that you can execute the procedure and display the
results.
Question: Create a stored procedure to insert a new order into the Orders table. The procedure should accept the customer_id, order_date, order_amount,
and status as parameters.
Question: Create a stored procedure to update the status of an order. The procedure should accept order_id and new_status as parameters.
Question: Create a stored procedure to delete an order based on order_id. The procedure should remove an order from the Orders table.
Question: Create a stored procedure that joins the Customers and Orders tables to display customer information along with their order details (order date,
amount, and status)
Summary of Tasks:
USE myDb;
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
phone_number VARCHAR(20),
address TEXT);
customer_id INT,
order_date DATE,
SHOW TABLES;
VALUES
VALUES
DELIMITER //
BEGIN
END //
DELIMITER ;
CALL SelectAllCustomers();
DELIMITER //
IN p_customer_id INT,
IN p_order_date DATE,
BEGIN
END //
DELIMITER ;
DELIMITER //
IN p_order_id INT,
BEGIN
UPDATE Orders
END //
DELIMITER ;
DELIMITER //
IN p_order_id INT)
BEGIN
END //
DELIMITER ;
CALL DeleteOrder(1);
DELIMITER //
BEGIN
SELECT
Customers c
END //
DELIMITER ;