About

A single logical operation on the data is called a transaction. A physical operation is called a request and therefore a transaction is a queue of request.

For example, a transfer of funds from one bank account to another, even though that might involve multiple changes (such as debiting one account and crediting another), is a single transaction.

A transaction has a beginning and an end.

This is the command pattern for data.

Example

A single transaction consists of one or more independent units of work, each reading and/or writing information to a database or other data store. When this happens it is often important to ensure that all such processing leaves the database or data store in a consistent state.

Examples from double-entry accounting systems often illustrate the concept of transactions. In double-entry accounting every debit requires the recording of an associated credit. If one writes a check for €100 to buy groceries, a transactional double-entry accounting system must record the following two entries to cover the single transaction:

  • Debit €100 to Groceries Expense Account
  • Credit €100 to Checking Account

A transactional system would make both entries — or both entries would fail. By treating the recording of multiple entries as an atomic transactional unit of work the system maintains the integrity of the data recorded. In other words, nobody ends up with a situation in which a debit is recorded but no associated credit is recorded, or vice versa.

Transaction Process

A simple transaction is usually issued to the database system in a language like SQL wrapped in a transaction, using a pattern similar to the following:

  • Begin the transaction
  • Execute several data manipulations and queries
  • If:
    • no errors occur, commit the transaction
    • errors occur then rollback the transaction
  • End the transaction

Purposes of Transactions

Transactions in a database environment have 4 purposes (Data Property - ACID (atomicity, consistency, isolation, durability))

  • atomicity: Transactions provide an “all-or-nothing” proposition, stating that each work-unit performed in a database must either complete in its entirety or have no effect whatsoever.
  • consistency: To provide reliable units of work that allow correct recovery from failures and keep a database consistent even in cases of system failure, when execution stops (completely or partially) and many operations upon a database remain uncompleted, with unclear status.
  • isolation: To provide isolation between programs accessing a database concurrently. Without isolation the programs' outcomes are possibly erroneous.

SQL Database

In the context of databases (“transactional databases”), a transaction is a logical, atomic unit of work that contains a series of SQL statements (one or more)

A database transaction consists of one or more statements. Specifically, a transaction consists of one of the following:

A commit ends the current transaction and makes permanent all changes performed in the transaction.

Documentation / Reference