Skip to content
Related Articles
Open in App
Not now

Related Articles

Transaction Management

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 14 Feb, 2022
Improve Article
Save Article

Transactions in DBMS : 
Transactions are a set of operations used to perform a logical set of work. A transaction usually means that the data in the database has changed. One of the major uses of DBMS is to protect the user’s data from system failures. It is done by ensuring that all the data is restored to a consistent state when the computer is restarted after a crash. The transaction is any one execution of the user program in a DBMS. Executing the same program multiple times will generate multiple transactions. 

Example – 
Transaction to be performed to withdraw cash from an ATM vestibule. 

Set of Operations : 
Consider the following example for transaction operations as follows. 

Example -ATM transaction steps. 

  • Transaction Start. 
  • Insert your ATM card. 
  • Select language for your transaction. 
  • Select Savings Account option. 
  • Enter the amount you want to withdraw. 
  • Enter your secret pin. 
  • Wait for some time for processing. 
  • Collect your Cash. 
  • Transaction Completed. 

Three operations can be performed in a transaction as follows. 

  1. Read/Access data (R). 
  2. Write/Change data (W). 
  3. Commit.

Example – 
Transfer of 50₹ from Account A to Account B. Initially A= 500₹, B= 800₹. This data is brought to RAM from Hard Disk. 

R(A) -- 500     // Accessed from RAM.
A = A-50        // Deducting 50₹ from A.
W(A)--450       // Updated in RAM.
R(B) -- 800     // Accessed from RAM.
B=B+50          // 50₹ is added to B's Account.
W(B) --850      // Updated in RAM.
commit          // The data in RAM is taken back to Hard Disk.

Note – 
The updated value of Account A = 450₹ and Account B = 850₹. 

All instructions before commit come under a partially committed state and are stored in RAM. When the commit is read the data is fully accepted and is stored in Hard Disk. 

If the data is failed anywhere before commit we have to go back and start from the beginning.  We can’t continue from the same state. This is known as Roll Back. 

Uses of Transaction Management : 

  • The DBMS is used to schedule the access of data concurrently. It means that the user can access multiple data from the database without being interfered with each other. Transactions are used to manage concurrency. 
  • It is also used to satisfy ACID properties. 
  • It is used to solve Read/Write Conflict. 
  • It is used to implement Recoverability, Serializability, and Cascading. 
  • Transaction Management is also used for Concurrency Control Protocols and Locking of data.

Transaction States : 
Transactions can be implemented using SQL queries and Server. In the below-given diagram, you can see how transaction states works. 

Transaction States

Disadvantage of using a Transaction : 

  • It may be difficult to change the information within the transaction database by end-users. 
  • We need to always roll back and start from the beginning rather than continue from the previous state.



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!