All Topics  
Database transaction

 

   Email Print
   Bookmark   Link






 

Database transaction



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

A database management system is computer software that manages databases. DBMSes may use any of a variety of database models, such as the network model or relational model....
 (or similar system) against a database, and treated in a coherent and reliable way independent of other transactions. Transaction
Transaction

A transaction is an agreement, communication, or movement carried out between separate entities or objects, often involving the exchange of items of value, such as information, goods, services and money....
s 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.






    Discussion
    Ask a question about 'Database transaction'
    Start a new discussion about 'Database transaction'
    Answer questions from other users
    Full Discussion Forum



    Encyclopedia


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

    A database management system is computer software that manages databases. DBMSes may use any of a variety of database models, such as the network model or relational model....
     (or similar system) against a database, and treated in a coherent and reliable way independent of other transactions. Transaction
    Transaction

    A transaction is an agreement, communication, or movement carried out between separate entities or objects, often involving the exchange of items of value, such as information, goods, services and money....
    s 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. Without isolation the programs' outcomes are typically erroneous.


    A database transaction, by definition, must be atomic, consistent, isolated and durable. Database practitioners often refer to these properties of database transactions using the acronym ACID
    Acid

    An acid is traditionally considered any chemical compound that, when dissolved in water, gives a solution with a hydrogen ion Activity greater than in pure water, i.e....
    .

    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.

    Some systems also refer to transactions as LUWs: Logical Units of Work.

    Purpose

    Database
    Database

    A database is a structured collection of records or data that is stored in a computer system. The structure is achieved by organizing the data according to a database model....
    s and other data stores which treat the integrity
    Data integrity

    Data integrity is a term used in computer science and telecommunications that can mean ensuring data is "whole" or complete, the condition in which data are identically maintained during any operation , the preservation of data for their intended use, or, relative to specified operations, the a priori expectation of data quality....
     of data as paramount often include the ability to handle transactions to maintain the integrity of data. 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 system
    Double-entry bookkeeping system

    Double-entry bookkeeping is a system of financial accounting where each transaction is recorded in at least two accounts: at least one account is Debits and credits and at least one account is Debits and credits, so that the total debits of the transaction equal to the total credits....
    s 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:

    1. Debit €100 to Groceries Expense Account
    2. 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.

    Transactional databases

    Most relational database management system
    Relational database management system

    A Relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular commercial and open source databases currently in use are based on the relational model....
    s fall into the category of databases that support transactions: transactional databases.

    In a database system a single transaction might consist of one or more data-manipulation statements and queries, each reading and/or writing information in the database. Users of database system
    Database system

    A database system is a term that is typically used to encapsulate the constructs of a data model, database Management system and database.A database is an organised pool of logically-related data....
    s consider consistency
    Data consistency

    Data consistency summarizes the validity, accuracy, usability and integrity of related data between applications and across the IT enterprise. This ensures that each user observes a consistent view of the data, including visible changes made by the user's own transactions and transactions of other users or processes....
     and integrity
    Data integrity

    Data integrity is a term used in computer science and telecommunications that can mean ensuring data is "whole" or complete, the condition in which data are identically maintained during any operation , the preservation of data for their intended use, or, relative to specified operations, the a priori expectation of data quality....
     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 several data manipulations and 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
    Rollback (data management)

    In database technologies, a rollback is an operation which returns the database to some previous state. Rollbacks are important for database data integrity, because they mean that the database can be restored to a clean copy even after erroneous operations are performed....
     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 transaction ID or XID.

    In SQL


    A START TRANSACTION statement in SQL
    SQL

    SQL is a database computer language designed for the retrieval and management of data in relational database management systems , database schema creation and modification, and database object access control management....
     or, on some systems, any statement that will modify data, starts a transaction
    Database transaction

    A database transaction comprises a unit of work performed within a database management system against a database, and treated in a coherent and reliable way independent of other transactions....
     within a relational database management system
    Relational database management system

    A Relational database management system is a database management system that is based on the relational model as introduced by E. F. Codd. Most popular commercial and open source databases currently in use are based on the relational model....
     (RDBMS).

    The result of any work done after this point will remain invisible to other database-users until the system processes a COMMIT statement. A ROLLBACK
    Rollback (data management)

    In database technologies, a rollback is an operation which returns the database to some previous state. Rollbacks are important for database data integrity, because they mean that the database can be restored to a clean copy even after erroneous operations are performed....
    statement can also occur, which will undo any work performed since the START TRANSACTION command. Both COMMIT and ROLLBACK will end the transaction: another START TRANSACTION will need to be issued to start a new one.

    Some database systems allow the synonyms BEGIN, BEGIN WORK and BEGIN TRANSACTION, and may have other options available.

    Distributed transactions


    Database systems implement distributed transaction
    Distributed transaction

    A distributed transaction is an operations bundle, in which two or more network hosts are involved. Usually, hosts provide transactional resources, while the transaction manager is responsible for creating and managing a global transaction that encompasses all operations against such resources....
    s as transactions against multiple applications or hosts. A distributed transaction enforces the ACID properties over multiple systems or data stores, and might include systems such as databases, file systems, messaging systems, and other applications. In a distributed transaction a coordinating service ensures that all parts of the transaction are applied to all relevant systems. As with database and other transactions, if any part of the transaction fails, the entire transaction is rolled back across all affected systems.

    Transactional filesystems


    The Namesys Reiser4
    Reiser4

    Reiser4 is a computer file system, successor to the ReiserFS file system, developed from scratch by Namesys and sponsored by Defense Advanced Research Projects Agency as well as Linspire....
     filesystem for Linux
    Linux

    Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
    and the version of the Microsoft NTFS
    NTFS

    NTFS is the standard file system of Windows NT, including its later versions Windows 2000, Windows XP, Windows Server 2003, Windows Server 2008, Windows Vista, and Windows 7....
     filesystem both support transactions, but file-system transactions are rarely used in practice due to lack of compatibility with older systems.

    External links