This question is from my database class; using SQL In this part we create a smal
ID: 3605801 • Letter: T
Question
This question is from my database class;
using SQL
In this part we create a small procedure:
Write a procedure that has as input the customer_id. Then the procedure should delete the corresponding customer from table customers.
Notice that customer_id is a foreign key on table orders. Therefore the customer cannot be deleted if he has placed orders. To delete a record from customers you should first delete the corresponding orders and to do that you need to first delete the corresponding order_details.
Now execute the procedure to delete customer with id 1. If you have solved part 01 a record will be inserted into Customer_Archives.
ROLLBACK; and all these changes will be undone!
Explanation / Answer
Answer is as follows:
CREATE OR REPLACE PROCEDURE Cust_Del ( Cust_Id IN NUMBER)
BEGIN
delete from order_details
where order_id in
( select order_id from orders where cust_id = p_cust_id );
delete from orders
where cust_id = p_cust_id;
delete from customers where cust_id = p_cust_id;
END;
CALL Cust_Del(01);
if there is any query please ask in comments....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.