Bird
0
0

Consider this SQL transaction:

medium📝 query result Q13 of 15
SQL - Transactions and Data Integrity
Consider this SQL transaction:
BEGIN TRANSACTION;
UPDATE inventory SET quantity = quantity - 5 WHERE product_id = 10;
UPDATE sales SET total = total + 5 WHERE sale_id = 3;
ROLLBACK;

What will be the final effect on the database?
ABoth updates will be saved permanently
BNo changes will be saved to the database
COnly the first update will be saved
DOnly the second update will be saved
Step-by-Step Solution
Solution:
  1. Step 1: Understand the effect of ROLLBACK

    ROLLBACK cancels all changes made in the current transaction, undoing updates.
  2. Step 2: Analyze the transaction steps

    Two updates happen, but ROLLBACK is called before COMMIT, so none of the changes are saved.
  3. Final Answer:

    No changes will be saved to the database -> Option B
  4. Quick Check:

    ROLLBACK cancels changes = C [OK]
Quick Trick: ROLLBACK undoes all changes in a transaction [OK]
Common Mistakes:
  • Assuming updates save without COMMIT
  • Thinking partial updates remain after ROLLBACK
  • Confusing ROLLBACK with COMMIT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes