You are on page 1of 2

A.1.

5 Database Transaction

A transaction comprises a unit of work performed within a database management system (or


similar system) against a database, and treated in a coherent and reliable way independent of
other transactions. Transactions in a database environment have two main purposes:

1. 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.
2. To provide isolation between programs accessing a database concurrently. If this
isolation is not provided, the program's outcome are possibly erroneous.

A database transaction, by definition, must be atomic, consistent, isolated and durable.[1]


Database practitioners often refer to these properties of database transactions using the
acronym ACID.

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. Further, the system
must isolate each transaction from other transactions, results must conform to existing
constraints in the database, and transactions that complete successfully must get written to
durable storage.

A transactional database is a DBMS where write transactions on the database are able to


be rolled back if they are not completed properly (e.g. due to power or connectivity loss).

Most modern relational database management systems fall into the category of databases


that support transactions.

In a database system a transaction might consist of one or more data-manipulation


statements and queries, each reading and/or writing information in the database. Users
ofdatabase systems consider consistency and integrity of data as highly important. 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:

1. Begin the transaction


2. Execute a set of data manipulations and/or queries
3. If no errors occur then commit the transaction and end it
4. If errors occur then rollback the transaction and end it

If no errors occurred during the execution of the transaction then the system commits the
transaction. A transaction commit operation applies all data manipulations within the scope
of the transaction and persists the results to the database. If an error occurs during the
transaction, or if the user specifies a rollback operation, the data manipulations within the
transaction are not persisted to the database. In no case can a partial transaction be
committed to the database since that would leave the database in an inconsistent state.

Internally, multi-user databases store and process transactions, often by using a


transactionID or XID.

There are multiple varying ways for transactions to be implemented other than the simple
way documented above. Nested transactions, for example, are transactions which contain
statements within them that start new transactions (i.e. sub-transactions). Multi-level
transactions are a variant of nested transactions where the sub-transactions take place at
different levels of a layered system architecture (e.g., with one operation at the database-
engine level, one operation at the operating-system level) [2] Another type of transaction is
the compensating transaction.

You might also like