×

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

Atomicity in Database Management System

In Database Management Systems, the term "atomicity" refers to the idea that database transactions are atomic units of work. This means that either all of the operations within a transaction...

10 minutes read.

Multivalued Dependency

Multivalued Dependency exists in a relation when two attributes depend on the third attribute but independent to each other. It is a full constraint between two sets of attributes in a relation. It...

2 minutes read.

Red-Black Tree Visualization in DBMS

Introduction to Red Black Tree A red-black tree is a self-balanced binary search tree with an extra bit per node, usually read as a color (red or black). The tree is...

4 minutes read.

Redundancy in DBMS

Data redundancy is a situation that is created in the database in which the same amount of data is stored in two different places. The different places are found in a...

3 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 Schedule

A schedule is a process of combining the multiple transactions into one and executing the operations of these transactions in a predefined order. A schedule can have multiple transactions in it, each transaction...

2 minutes read.

Relational algebra in DBMS

Relational algebra in DBMS Relational algebra is a procedural query language used to retrieve the data from a database in a different way. It works on the relational model. It performs...

3 minutes read.

ER Diagram for School Management System in DBMS

What is ER Diagram? An ERD, or entity relationship diagram, is a diagram that depicts the connections between a group of entities contained in a database. In other words, ER diagrams...

6 minutes read.

ER Diagram for Student Management System in DBMS

Entity Relationship diagrams Entity Relationship Diagrams, or ER Diagrams for short, are diagrams that show the relationships among entity sets that are stored in databases. Alternatively said, ER diagrams assist in...

6 minutes read.

B-Tree Insertion in DBMS

A B-tree is a special type of m-way tree, commonly used for disk access. A B-tree of order m can have at most m-1 keys and m descendants. B-trees are...

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.

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.

Functional Dependencies

Functional Dependencies (FD) in the relational database management system occurs when one attribute in a relation uniquely determines other attribute in that relation. It describes the relation between the attributes. The term functional...

2 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.

Integrity Constraints in DBMS

Integrity constraints in DBMS (Database Management System) are used to ensure the accuracy and consistency of data in a database. They are a set of rules that define the allowed...

1 minute read.

How to draw ER-Diagram in DBMS?

Entity Relationship Diagrams, or ERDs, are diagrams that assist you in visualizing your database design. An ERD, also called anER diagram or ER model,describes data and how parts of the data interact. ERDs are crucial in database architecture and projects that call for...

9 minutes read.

Fundamentals Of Distributed DBMS

Fundamentals of DDBMS Here we are going to talk about the Fundamentals of DDBMS. But first, we need to know about Distributed databases to understand the Distributed Database Management System. Distributed Database: It is...

4 minutes read.

Deadlock in DBMS

Deadlock in DBMS A deadlock is an unwanted condition in which two or more transaction are waiting indefinitely for one another to give up locks. It is said to be one of the...

3 minutes read.

Domain in DBMS

Constraints: Constraints in DBMS are a set of guidelines that guarantee that authorized users who modify the database do not alter the consistency of the data. Constraints are expressed in DDL...

3 minutes read.

Attributes in DBMS

What is Attribute? An attribute is an element in the database management system that describes the property or certain characteristics of the database entity. It is a crucial element of the...

3 minutes read.