Answer: Using SAVEPOINT
Explore how to implement SAVEPOINT to manage transactions in MySQL effectively. Understand creating savepoints, rolling back to them, and using session variables to handle intermediate states. This lesson helps you master transaction control techniques, ensuring atomic updates while allowing partial rollback for data integrity.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 1: Starts a new transaction so that all following operations are grouped into one atomic unit of work that can be committed or rolled back together.
Lines 4–7: Select the current
QuantityandStockvalues forOrderID = 3andProductID = 3. The values are stored in session variables@orig_qtyand@orig_stockfor later comparison.Lines 10–12: Update the ...