Transaction semantics: Is a transaction a series of database actions that must all succeed together, or else none take effect (all-or-nothing)?
-
ACorrect
-
BIncorrect
-
COnly for read-only transactions
-
DOnly when autocommit is off
Answer
Correct Answer: Correct
Explanation
Introduction / Context:Transactions provide a clean unit of work in database systems. The key property highlighted here is atomicity: a transaction’s changes are applied entirely or not at all. This property underpins reliable application behavior in the face of errors or crashes.
Given Data / Assumptions:
- A transaction encloses multiple reads and writes.
- Commit makes changes durable; rollback undoes them.
- System may crash, but recovery respects atomicity.
Concept / Approach:ACID stands for Atomicity, Consistency, Isolation, Durability. Atomicity is the “all-or-nothing” guarantee. Consistency requires that transactions move the database from one valid state to another, Isolation controls interference among concurrent transactions, and Durability guarantees that committed changes persist.
Step-by-Step Solution:
Group operations into a transaction (BEGIN/START TRANSACTION).On success, COMMIT to make changes permanent.On failure, ROLLBACK to cancel all effects.Verification / Alternative check:Crash recovery replays/undoes logged operations to ensure either the full transaction is applied or not applied, never a partial state.
Why Other Options Are Wrong:
- “Incorrect” contradicts the definition of atomicity.
- Transaction semantics do not apply “only for read-only” or depend solely on autocommit; even with autocommit, each statement is a transaction.
Common Pitfalls:Mistaking batch execution for transactional grouping. Without explicit transaction control, some drivers autocommit per statement; still, each statement is atomic.
Final Answer:Correct