×

What is Transaction in DBMS

A transaction is a collection of logically related operations which reads and possibly updates the various data items in the database. Usually, a transaction is initiated by a user program written in high-level DML language (SQL), or programming language, with an embedded database, accesses in JDBC or ODBC.

In other words, we can say that any logical calculation which is done in a consistent mode in the database is called a transaction. Every database before and after the transaction must be in a consistent state.

A transaction has the following properties to ensure the integrity of data:

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability

Simple Transaction Example

Suppose a bank employee transfers money from X’s account to Y’s account. As the amount of 100Rs gets transferred from the X account to Y’s account, the following series of operations are performed in the background of the screen.

Simply we can say, the transaction involves many following operations such as:

  1. Open the account of X
  2. Read the old balance
  3. Deduct the certain amount 100Rs from X account
  4. saving new balance to X account
  5. Open the account of Y
  6. Read the old balance
  7. Add the certain amount 100Rs to Y’s account
  8. Save new balance to Y account

X’s Account

Open_Account(X)
Old_Balance = X.balance
New_Balance = Old_Balance - 100
X.balance = New_Balance
Close_Account(X) 

Y’s Account

Open_Account(Y)
Old_Balance = Y.balance
New_Balance = Old_Balance + 100
Y.balance = New_Balance
Close_Account(Y) 

Operations of transaction

Following are the two main operations in a transaction:

  1. Read operation
  2. Write operation

Read Operation: This operation transfers the data item from the database and then stores it in a buffer in main memory.

Write Operation: This operation writes the updated data value back to the database from the buffer.

For example: Let Ti be a transaction that transfer Rs50 from X account to Y account. This transaction can be defined as:

T i: read(X); …….(1)
X := X?50; …….(2)
write(X); …….(3)
read(Y); …….(4)
Y := Y + 50; …….(5)
write(Y).…….(6)

Assume that the value of both X and Y before starting of the transaction Ti is 100.

  • The first operation read the value of X(100) from the database and stores it in a buffer. The second operation will decrease X value by 50. So buffer will contain 50. The third operation will write the value of the buffer to the database. So the final value of X will be 50.
  • The fourth operation read the value of Y(100) from the database and stores it in a buffer.The fifth operation will add X value by 50. So buffer will contain 150. The sixth operation will write the value of buffer to the database. So the final value of Y will be 150.

But, it may be possible that due to hardware or software failure that transaction may fail before completing all the operations in the set.
For example: If in the above transaction, the transaction fails after executing operation 5, then Y's value will remain 100 in the database, which is not acceptable by the bank.

To overcome this problem, we have two important operations Commit and Rollback.
Commit Operation: This operation is used to save the work done permanently in the database.
Rollback Operation: This operation is used to undo the work done.


Related Topics

Domain Constraints in DBMS

Introduction about DBMS:- DBMS stands for DataBase Management System. DBMS(DataBase Management System) is a type of software by which we can save and retrieve the user's data with the security process....

3 minutes read.

3- Tier Architecture in DBMS

Three-tier architecture is an application software architecture that arranges the output into three parts or tiers that are:  the presentation tier, where the user interacts with the application; the application...

4 minutes read.

Query processing in DBMS

Operations on DBMSs are made much simpler, more organized, and methodical with SQL. These are not only simpler for people to comprehend, but after gaining a basic comprehension of them, they...

4 minutes read.

View Serializability in DBMS

View Serializability It is a type of serializability that can be used to check whether the given schedule is view serializable or not. A schedule called as a view serializable if it is view...

4 minutes read.

Normalization in DBMS: 1NF, 2NF, 3NF, BCNF & 4NF with Examples

Normalization is a technique of organizing the data in the database. It is a systematic approach which is used to remove or reduce data redundancy in the tables and remove the...

7 minutes read.

DBMS Keys: Primary, Super, Candidate, Foreign

In database management system, keys play an important role which is used for identifying unique records by the combination of one or more fields in the database table. Keys also allows you to...

3 minutes read.

Relational DBMS Concepts

What is RDBMS? RDBMS stands for Relational Database Management System.The relational database management system is a type of DBMS that stores information in the form of related tables and uses a...

3 minutes read.

ER Diagram for University Database in DBMS

What is an ER diagram? ER diagram, short for Entity Relationship Diagram, also known as ERD, is a diagram that shows the relationships of a set of entities stored in a...

9 minutes read.

DBMS Data Independence: Logical and Physical

Data Independence in DBMS: Data independence is a concept of DBMS which alters the schema of the database at one level of the database system without altering the schema definition...

2 minutes read.

Fragmentation in Distributed DBMS

Fragmentation is a course of isolating the entire or full information base into different sub tables or sub relations with the goal that information can be put away in various...

4 minutes read.

Components of Relational Database Management System

A relational database management system compromises various component. Tables, records, attributes, instances, schemas and keys together form a relational database. In this page, we will discuss each component of RDBMS in...

4 minutes read.

Evaluating DBMS

There are various database management systems available in the market. Each type has its features and can be used for varied purposes. The large number of DBMS makes it difficult...

4 minutes read.

What is RDBMS?

To discuss the Relational Database Management System, there are some terms and concepts you need to know. Database Any collection of related information is called a database. The phone book is...

5 minutes read.

Primary Key in DBMS

Primary Key in DBMS: A primary key is the minimal set of columns in the database table, which uniquely identifies each row or tuple in that table. Any table in...

2 minutes read.

Concurrent Execution of Transaction

In the transaction process, a system usually allows executing more than one transaction simultaneously. This process is called a concurrent execution. Advantages of concurrent execution of a transaction Decrease waiting time or...

4 minutes read.

Foreign key in DBMS

Foreign key in DBMS: The Foreign key is a field or the set of fields in the relational database table, which points to the existing field in another table. It...

2 minutes read.

Candidate Key in DBMS

Candidate key in DBMS: The candidate key is a single column or the set of columns that uniquely identifies the rows of data in the database table. It is a...

2 minutes read.

DBMS Architecture

This is the first step when creating a database management system. The architecture of a database management system plays an important role in determining the actual design and layout of...

4 minutes read.

Advantages and Disadvantages of DBMS

We need to understand what is Database Management System before discussing the advantages and disadvantages of the database management system, and also, need to understand what were the technologies and...

5 minutes read.

States of Transaction in DBMS

Transaction States A transaction passes through many different states in its life cycle. These states are known as transaction states. A transaction can be in one of the following states in the database: Active statePartially...

3 minutes read.