Share via


Data Access and Transactions

cc961189(v=technet.10).md

Transactions Explained

A transaction, simply put, is an all or nothing sequence of database transformations. No modifications are committed to the database until all steps of the transaction have completed successfully. If any of the actions cannot be completed, the entire transaction is automatically rolled back, or undone. Transactions are a technique applied to guarantee the correctness of database operations.

The properties of transactions are collectively known by the acronym ACID:

  • Atomicity    Transactions are either committed or rolled back as a whole. Unless all database transformations are successful, none of them will be committed to the database.

  • Consistency    A transaction never leaves the system in a state that cannot be recovered if the transaction fails.

  • Isolation    Until the transaction has completed successfully, its modifications are not visible to other users.

  • Durability    Committed transactions persist beyond any subsequent software or hardware failures. Transactions that have not committed are rolled back when the system is restarted.

At the most basic level, transactions ensure that data is protected from accidental modifications that would invalidate it. If an event occurs that upsets the intended sequence of changes, all the previous changes can be undone to restore the database to its original form. What happens if the second (or third) update fails? What if the application that is making changes crashes? What if the computer is accidentally turned off? Transactions that are stopped short are guaranteed to have no lasting effect on your data.

A transaction defines a boundary that encapsulates several database interactions and makes them appear as a single atomic interaction. Once a transaction has begun, an application can make changes to multiple records, and the effect of these changes is isolated from the rest of the database and from other users. When the transaction is committed, all the changes appear to happen simultaneously, in such a way as to guarantee that no data is lost or compromised.

Although transactions are important in commerce, transactions arent just about money. They arbitrate the contention that occurs with demand for any hard resource that cannot be created or destroyed.

See the following: