Question: Exercises Write a script that creates and calls a stored procedure named test. This procedure should include two SQL statements coded as a transaction to
Exercises
Write a script that creates and calls a stored procedure named test. This procedure should include two
SQL statements coded as a transaction to delete the row with a customer ID of from the Customers
table. To do this, you must first delete all addresses for that customer from the Addresses table.
If these statements execute successfully, commit the changes. Otherwise, roll back the changes.
Write a script that creates and calls a stored procedure named test. This procedure should include
these statements coded as a transaction:
INSERT INTO orders VALUES
DEFAULT NOW NULL
'American Express', ;
SELECT LASTINSERTID
INTO orderd;
INSERT INTO order items VALUES
DEFAULT order;
INSERT INTO order items VALUES
DEFAULT order;
Here, the LASTINSERTID function is used to get the order ID value that's automatically generated
when the first INSERT statement inserts an order.
If these statements execute successfully, commit the changes. Otherwise, roll back the changes.
Write a script that creates and calls a stored procedure named test. This procedure should use a
transaction that includes the statements necessary to combine two customers. These statements should
do the following:
Select a row from the Customers table for the customer with a customerid value of This
statement should lock the row so other transactions can't read or modify it until the transaction
commits, and it should fail immediately if the row is locked from another session.
Update the Orders table so any orders for the selected customer are assigned to the customer with
a customerid value of
Update the Addresses table so any addresses for the selected customer are assigned to the
customer with a customerid value of
Delete the selected customer from the Customers table.
If these statements execute successfully, commit the changes. Otherwise, rollback the changes.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
