Bird
0
0

Why do we need transactions in a database?

easy📝 Conceptual Q11 of 15
SQL - Transactions and Data Integrity
Why do we need transactions in a database?
BEGIN TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT;
ATo make sure all steps succeed or none do, keeping data correct
BTo speed up the database queries
CTo allow multiple users to read data at the same time
DTo permanently delete data from the database
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of transactions

    Transactions group multiple steps so they all succeed or all fail together, preventing partial updates.
  2. Step 2: Analyze the example code

    The example moves money between accounts; if one update fails, the transaction rolls back to keep balances correct.
  3. Final Answer:

    To make sure all steps succeed or none do, keeping data correct -> Option A
  4. Quick Check:

    Transactions ensure data integrity = A [OK]
Quick Trick: Transactions keep data safe by grouping steps [OK]
Common Mistakes:
  • Thinking transactions speed up queries
  • Confusing transactions with data deletion
  • Believing transactions only allow multiple readers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes