Codacoda
Back to Academy

relational database

Transactions

A database transaction is a sequence of operations treated as a single logical unit. BEGIN starts the transaction, COMMIT makes all changes permanent, and ROLLBACK undoes everything if an error occurs. Transaction logs record every operation, enabling recovery and audit trails.

Use Cases

  • Processing multi-step e-commerce checkouts where inventory, payment, and shipping must all succeed
  • Implementing undo functionality by rolling back to a previous state
  • Maintaining audit trails of every data modification for compliance
  • Ensuring database recovery after a crash by replaying the transaction log

Visualization

BEFOREapplies totransaction logseqtxnactionstatusitemsidnameqty1Apple102Banana5
Speed:1x
Two concurrent transactions will modify the items tableStep 1 / 7

Implementation

Output

Click "Run Code" to see output...