What is Transaction?
A series of operations on a database treated as a single unit. COMMIT makes the results permanent, and ROLLBACK returns the data to its state before the transaction began. The DBMS manages transactions with locks and logs so that they satisfy atomicity, consistency, isolation and durability (the ACID properties).
Japanese name: トランザクション
Transaction appears in 13 practice questions across 1 topic, including Database Basics.
Field: Database Basics
COMMIT and ROLLBACK
In a transfer between accounts, the result is correct only when both the debit from account A and the credit to account B have been made. A transaction groups such a series of operations into one unit: executing COMMIT at the end makes the results permanent, and executing ROLLBACK, for example when an error occurs partway through, cancels every update in the transaction. Uncommitted updates are also cancelled if a failure occurs, so no half-finished state with only some updates applied remains.
FAQ
What happens if an error occurs partway through a transaction?
Either the application executes ROLLBACK or the DBMS performs failure recovery, and every update in that transaction is cancelled. Only some of the updates are never left behind.
What problems arise from making a transaction long?
It holds locks for a long time, so other transactions wait, less work can be processed concurrently, and deadlocks become more likely. As a rule, a transaction should be kept as short as is needed to maintain consistency.