What are Transactions in DBMS?
A small unit of a program that contains several low level tasks are called Transactions.
Basic Concept of transaction :
- A transaction is a unit of program execution that accesses and possibly updates various data items in a database.
- Example :
- Transaction to transfer ₹50 from account A to account B:
- A:= A – 50
- B := B + 50
Two main issues to deal with:
- Failures of various kinds, such as hardware failures and system crashes or software error.
- Concurrent execution of multiple transactions (Concurrency Control)
- Process of Transaction:
- The transaction is executed as a series of reads and writes of database objects, which are explained below:
- read(X), which transfers the data item X from the database to a variable, also called X, in a buffer in main memory belonging to the transaction that executed the read operation.
- write(X), which transfers the value in the variable X in the main-memory buffer of the transaction that executed the write to the data item X in the database.
To preserve the integrity of data the database system must ensure:
- Atomicity (all or nothing): Either all operations of the transaction are properly reflected in the database or none are.
It involves the following two operations.
—Abort: If a transaction aborts, changes made to the database are not visible.
—Commit: If a transaction commits, changes made are visible.
- Consistency (No violation of integrity constraints): Execution of a transaction in isolation preserves the consistency of the database.
- Isolation (concurrent changes invisible): Although multiple transactions may execute concurrently, each transaction must be unaware of other concurrently executing transactions. Intermediate transaction results must be hidden from other concurrently executed transactions. That is, for every pair of transactions Ti and Tj, it appears to Ti that either Tj finished execution before Ti started, or Tj started execution after Ti finished.
- Durability (committed update persist): After a transaction completes successfully, the changes it has made to the database persist, even if there are system failures.
These properties are called ACID properties.