The Wayback Machine - https://web.archive.org/web/20241011193908/https://www.geeksforgeeks.org/transaction-in-dbms/
Open In App

Transaction in DBMS

Last Updated : 29 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In Database Management Systems (DBMS), a transaction is a fundamental concept representing a set of logically related operations executed as a single unit. Transactions are essential for handling user requests to access and modify database contents, ensuring the database remains consistent and reliable despite various operations and potential interruptions.

In this article, we will discuss what a transaction means, various operations of transactions, transaction states, and properties of transactions in DBMS.

What does a Transaction mean in DBMS?

  • Transaction in Database Management Systems (DBMS) can be defined as a set of logically related operations.
  • It is the result of a request made by the user to access the contents of the database and perform operations on it.
  • It consists of various operations and has various states in its completion journey.
  • It also has some specific properties that must be followed to keep the database consistent.

Operations of Transaction

A user can make different types of requests to access and modify the contents of a database. So, we have different types of operations relating to a transaction. They are discussed as follows:

i) Read(X)

  • A read operation is used to read the value of X from the database and store it in a buffer in the main memory for further actions such as displaying that value.
  • Such an operation is performed when a user wishes just to see any content of the database and not make any changes to it. For example, when a user wants to check his/her account’s balance, a read operation would be performed on user’s account balance from the database.

ii) Write(X)

  • A write operation is used to write the value to the database from the buffer in the main memory. For a write operation to be performed, first a read operation is performed to bring its value in buffer, and then some changes are made to it, e.g. some set of arithmetic operations are performed on it according to the user’s request, then to store the modified value back in the database, a write operation is performed.
  • For example, when a user requests to withdraw some money from his account, his account balance is fetched from the database using a read operation, then the amount to be deducted from the account is subtracted from this value, and then the obtained value is stored back in the database using a write operation.

iii) Commit

  • This operation in transactions is used to maintain integrity in the database. Due to some failure of power, hardware, or software, etc., a transaction might get interrupted before all its operations are completed. This may cause ambiguity in the database, i.e. it might get inconsistent before and after the transaction.
  • To ensure that further operations of any other transaction are performed only after work of the current transaction is done, a commit operation is performed to the changes made by a transaction permanently to the database.

iv) Rollback

  • This operation is performed to bring the database to the last saved state when any transaction is interrupted in between due to any power, hardware, or software failure.
  • In simple words, it can be said that a rollback operation does undo the operations of transactions that were performed before its interruption to achieve a safe state of the database and avoid any kind of ambiguity or inconsistency.

Transaction Schedules

When multiple transaction requests are made at the same time, we need to decide their order of execution. Thus, a transaction schedule can be defined as a chronological order of execution of multiple transactions.

There are broadly two types of transaction schedules discussed as follows:

i) Serial Schedule

  • In this kind of schedule, when multiple transactions are to be executed, they are executed serially, i.e. at one time only one transaction is executed while others wait for the execution of the current transaction to be completed. This ensures consistency in the database as transactions do not execute simultaneously.
  • But, it increases the waiting time of the transactions in the queue, which in turn lowers the throughput of the system, i.e. number of transactions executed per time.
  • To improve the throughput of the system, another kind of schedule are used which has some more strict rules which help the database to remain consistent even when transactions execute simultaneously.

ii) Non-Serial Schedule

  • To reduce the waiting time of transactions in the waiting queue and improve the system efficiency, we use nonserial schedules which allow multiple transactions to start before a transaction is completely executed. This may sometimes result in inconsistency and errors in database operation.
  • So, these errors are handled with specific algorithms to maintain the consistency of the database and improve CPU throughput as well.
  • Non-serial schedules are also sometimes referred to as parallel schedules, as transactions execute in parallel in these kinds of schedules.

Serializable

  • Serializability in DBMS is the property of a nonserial schedule that determines whether it would maintain the database consistency or not.
  • The nonserial schedule which ensures that the database would be consistent after the transactions are executed in the order determined by that schedule is said to be Serializable Schedules.
  • The serial schedules always maintain database consistency as a transaction starts only when the execution of the other transaction has been completed under it.
  • Thus, serial schedules are always serializable.
  • A transaction is a series of operations, so various states occur in its completion journey. They are discussed as follows:

i) Active

  • It is the first stage of any transaction when it has begun to execute. The execution of the transaction takes place in this state.
  • Operations such as insertion, deletion, or updation are performed during this state.
  • During this state, the data records are under manipulation and they are not saved to the database, rather they remain somewhere in a buffer in the main memory.

ii) Partially Committed

  • This state of transaction is achieved when it has completed most of the operations and is executing its final operation.
  • It can be a signal to the commit operation, as after the final operation of the transaction completes its execution, the data has to be saved to the database through the commit operation.
  • If some kind of error occurs during this state, the transaction goes into a failed state, else it goes into the Committed state.

iii) Commited

This state of transaction is achieved when all the transaction-related operations have been executed successfully along with the Commit operation, i.e. data is saved into the database after the required manipulations in this state. This marks the successful completion of a transaction.

iv) Failed

  • If any of the transaction-related operations cause an error during the active or partially committed state, further execution of the transaction is stopped and it is brought into a failed state. Here, the database recovery system makes sure that the database is in a consistent state.

v) Aborted

If the error is not resolved in the failed state, then the transaction is aborted and a rollback operation is performed to bring database to the the last saved consistent state. When the transaction is aborted, the database recovery module either restarts the transaction or kills it.

The illustration below shows the various states that a transaction may encounter in its completion journey.

Transaction-in-dbms

Transaction in DBMS

Properties of Transaction

  • As transactions deal with accessing and modifying the contents of the database, they must have some basic properties which help maintain the consistency and integrity of the database before and after the transaction. Transactions follow 4 properties, namely, Atomicity, Consistency, Isolation, and Durability.
  • Generally, these are referred to as ACID properties of transactions in DBMS. ACID is the acronym used for transaction properties. A brief description of each property of the transaction is as follows.

i) Atomicity

  • This property ensures that either all operations of a transaction are executed or it is aborted. In any case, a transaction can never be completed partially.
  • Each transaction is treated as a single unit (like an atom). Atomicity is achieved through commit and rollback operations, i.e. changes are made to the database only if all operations related to a transaction are completed, and if it gets interrupted, any changes made are rolled back using rollback operation to bring the database to its last saved state.

ii) Consistency

  • This property of a transaction keeps the database consistent before and after a transaction is completed.
  • Execution of any transaction must ensure that after its execution, the database is either in its prior stable state or a new stable state.
  • In other words, the result of a transaction should be the transformation of a database from one consistent state to another consistent state.
  • Consistency, here means, that the changes made in the database are a result of logical operations only which the user desired to perform and there is not any ambiguity.

iii) Isolation

  • This property states that two transactions must not interfere with each other, i.e. if some data is used by a transaction for its execution, then any other transaction can not concurrently access that data until the first transaction has completed.
  • It ensures that the integrity of the database is maintained and we don’t get any ambiguous values. Thus, any two transactions are isolated from each other.
  • This property is enforced by the concurrency control subsystem of DBMS.

iv) Durability

  • This property ensures that the changes made to the database after a transaction is completely executed, are durable.
  • It indicates that permanent changes are made by the successful execution of a transaction.
  • In the event of any system failures or crashes, the consistent state achieved after the completion of a transaction remains intact. The recovery subsystem of DBMS is responsible for enforcing this property.

Conclusion

Transactions in DBMS are pivotal in maintaining the integrity and consistency of the database through a series of well-defined operations and states. From the initial execution of operations to handling errors and ensuring consistency, transactions must adhere to the ACID properties—Atomicity, Consistency, Isolation, and Durability. These properties guarantee that transactions are processed reliably and that the database remains stable even in the face of failures or concurrent operations.

FAQs on Transaction in DBMS

What is meant by a transaction in DBMS?

In DBMS, a transaction is a set of logical operations performed to access and modify the contents of the database as per the user’s request.

What is meant by ACID properties in transactions?

ACID is an acronym used for the properties of transaction in DBMS. It is used to denote the properties of transactions, i.e. Atomicity, Consistency, Isolation and Durability.

Which operation of transactions ensures the durability property?

In DBMS, the durability of a transaction, i.e. the changes made by it are saved to the database permanently, is ensured by the ‘Commit’ operation. A transaction is completed only if data is saved using ‘Commit’ operation. And then, the changes remain durable, i.e. in case of any system failures, the last saved state of the database can be recovered through database recovery subsystem in DBMS.

What is meant by schedules of transactions in DBMS?

When multiple transaction requests are made at the same time, we need to decide the order of execution of these transactions. This chronological order of execution of transactions is called as a schedule of transactions in DBMS. It is mainly of two types, i.e. Serial Schedules and Non Serial Schedules.

What do you mean by serializability in DBMS?

Serializability is the property of a schedule of transactions in DBMS which determines whether the database would be in consistent state or not if the transactions are executed following the given schedule.



Similar Reads

On Line Transaction Processing (OLTP) System in DBMS
On-Line Transaction Processing (OLTP) System refers to the system that manage transaction oriented applications. These systems are designed to support on-line transaction and process query quickly on the Internet. For example: POS (point of sale) system of any supermarket is a OLTP System. Every industry in today's world use OLTP system to record t
3 min read
Transaction Control in DBMS
The transaction is a single logical unit that accesses and modifies the contents of the database. Transactions access data using read and write operations. Transaction is a single operation of processing that can have many operations. Transaction is needed when more than one user wants to access same database. Transaction has ACID properties. ACID
5 min read
Transaction Isolation Levels in DBMS
The levels of transaction isolation in DBMS determine how the concurrently running transactions behave and, therefore, ensure data consistency with performance being even. There are four basic levels- Read Uncommitted, Read Committed, Repeatable Read, and Serializable that provide different degrees of data protection from providing fast access with
7 min read
Transaction States in DBMS
Transaction in DBMS is a set of logically related operations executed as a single unit. These logic are followed to perform modification on data while maintaining integrity and consistency. Transactions are performed in a way that concurrent actions from different users don't malfunction the database. Transfer of money from one account to another i
4 min read
Two Phase Commit Protocol (Distributed Transaction Management)
Consider we are given with a set of grocery stores where the head of all store wants to query about the available sanitizers inventory at all stores in order to move inventory store to store to make balance over the quantity of sanitizers inventory at all stores. The task is performed by a single transaction T that's component Tn at the nth store a
5 min read
Introduction to Transaction Processing
Single user system : In this at-most, only one user at a time can use the system. Multi-user system : In the same, many users can access the system concurrently. Concurrency can be provided through : Interleaved Processing - In this, the concurrent execution of processes is interleaved in a single CPU. The transactions are interleaved, meaning the
2 min read
Recovery from failures in Two Phase Commit Protocol (Distributed Transaction)
Prerequisite: Two-Phase Commit ProtocolIn the 2-phase commit protocol, the sites contributing to a distributed transaction and the coordinator that is managing the whole transaction globally may fail or crash, and this could lead to the whole transaction failure. Since unanimity is required in order to commit a distributed transaction successfully
4 min read
SQLite Transaction
SQLite is a database engine. It is a software that allows users to interact with relational databases. Basically, it is a serverless database which means it does not require any server to process queries. With the help of SQLite, we can develop embedded software without any configurations. SQLite is preferable for small datasets. SQLite is a portab
5 min read
SQL Server Transaction
Multiple SQL queries in a group in SQL Server may need to execute and out of the SQL Queries in the group, some of the queries may fail. This could create data update issues and data consistency issues as a partial update could make a series of transactions incomplete. So, there is an SQL Statement called TRANSACTION with COMMIT and ROLLBACK, which
5 min read
How do Database Systems Handle Transaction Failures?
Answer: Database systems handle transaction failures through two mechanisms, rollback and logging.Database systems handle transaction failures by leveraging the ACID (Atomicity, Consistency, Isolation, Durability) properties to ensure data integrity and system reliability. When a transaction fails, the system employs two critical mechanisms: rollba
1 min read
Online Transaction Processing (OLTP) and Online Analytic Processing (OLAP)
Online Transaction Processing (OLTP): OLTP databases are meant to be used to do many small transactions, and usually serve as a "single source of storage". An example of OLTP system is online movie ticket booking website. Suppose two persons at the same time wants to book the same seat for the same movie for same movie timing then in this case whoe
5 min read
MySQL Transaction
Essentially, a database transaction is a kind of safe wherein you perform a lot of operations—for instance, money transfers—in one shot. If everything goes fine, it saves all the changes; otherwise, in case something goes wrong, the database rolls back to its old state in order to make sure that your money doesn't disappear into thin air. MySQL is
5 min read
Difference between Data Warehousing and Online transaction processing (OLTP)
Information is crucial to today’s organizations and acts as the base for their decisions, work, and planning. Two minor systems that are useful in managing this data include Data Warehousing (DWH) as well as Online Transaction Processing (OLTP). Though both systems are essential, they serve distinct purposes: Essentially, DWH deals with data and de
3 min read
Transaction Management
Transactions are a set of operations used to perform a logical set of work. It is the bundle of all the instructions of a logical operation. 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
9 min read
Thomas Write Rule in DBMS
The "write rule" in database management systems (DBMS) refers to a principle that governs how changes to the database are handled. Specifically, the write rule states that any modification to a database must be written to disk before control is returned to the user. In other words, when a user executes a command that modifies the database (such as
5 min read
Armstrong's Axioms in Functional Dependency in DBMS
Prerequisite - Functional Dependencies This article contains Armstrong's Axioms and how Armstrong's Axioms are used to decide about the functional dependency on the database. We will be also learning about the Secondary Rules and Armstrong Relations. We will learn each thing in detail. Before moving ahead, you must have a knowledge of Functional De
4 min read
Database Objects in DBMS
A database object is any defined object in a database that is used to store or reference data.Anything which we make from create command is known as Database Object.It can be used to hold and manipulate the data.Some of the examples of database objects are : view, sequence, indexes, etc. Table - Basic unit of storage; composed rows and columns View
4 min read
Starvation in DBMS
Starvation or Livelock is the situation when a transaction has to wait for an indefinite period of time to acquire a lock. Reasons for Starvation:If the waiting scheme for locked items is unfair. ( priority queue )Victim selection (the same transaction is selected as a victim repeatedly )Resource leak.Via denial-of-service attack.Starvation can be
5 min read
Graph Based Concurrency Control Protocol in DBMS
Graph-based concurrency control protocols are used in database management systems (DBMS) to ensure that concurrent transactions do not interfere with each other and maintain the consistency of the database. In graph-based concurrency control, transactions are represented as nodes in a graph, and the conflicts between transactions are represented as
4 min read
Introduction to TimeStamp and Deadlock Prevention Schemes in DBMS
Deadlock occurs when each transaction T in a schedule of two or more transactions waiting for some item locked by some other transaction T' in the set. Thus, both end up in a deadlock situation, waiting for the other to release the lock on the item. Deadlocks are a common problem and we have introduced the problem while solving the Concurrency Cont
7 min read
Implementation of Locking in DBMS
Locking protocols are used in database management systems as a means of concurrency control. Multiple transactions may request a lock on a data item simultaneously. Hence, we require a mechanism to manage the locking requests made by transactions. Such a mechanism is called a Lock Manager. It relies on the process of message passing where transacti
5 min read
Tuple Relational Calculus (TRC) in DBMS
Tuple Relational Calculus (TRC) is a non-procedural query language used in relational database management systems (RDBMS) to retrieve data from tables. TRC is based on the concept of tuples, which are ordered sets of attribute values that represent a single row or record in a database table. TRC is a declarative language, meaning that it specifies
4 min read
Fragmentation in Distributed DBMS
Fragmentation is a process of dividing the whole or full database into various subtables or sub relations so that data can be stored in different systems. The small pieces or sub relations or subtables are called fragments. These fragments are called logical data units and are stored at various sites. It must be made sure that the fragments are suc
5 min read
Challenges of database security in DBMS
Seeing the vast increase in volume and speed of threats to databases and many information assets, research efforts need to be consider to the following issues such as data quality, intellectual property rights, and database survivability. Let's discuss them one by one. 1. Data quality - The database community basically needs techniques and some org
5 min read
Schema Integration in DBMS
Definition: Schema integration is used to merge two or more database schemas into a single schema that can store data from both the original databases. For large databases with many expected users and applications, the integration approach of designing individual schema and then merging them can be used. Because the individual views can be kept rel
5 min read
Domain Key Normal Form in DBMS
Prerequisites - Normal Forms, 4th and 5th Normal form, find the highest normal form of a relation It is basically a process in database to organize data efficiently. Basically there are two goals of doing normalization these are as follows: To remove repeated data or in simple words we can say to remove redundant data.Second one is to ensure that t
4 min read
Interfaces in DBMS
A database management system (DBMS) interface is a user interface that allows for the ability to input queries to a database without using the query language itself. User-friendly interfaces provided by DBMS may include the following: Menu-Based InterfacesForms-Based InterfacesGraphical User InterfacesNatural Language InterfacesSpeech Input and Out
4 min read
Why recovery is needed in DBMS
Basically, whenever a transaction is submitted to a DBMS for execution, the operating system is responsible for making sure or to be confirmed that all the operations which need to be performed in the transaction have been completed successfully and their effect is either recorded in the database or the transaction doesn't affect the database or an
6 min read
Economic factors (Choice of DBMS)
Basically, the choice of a DBMS is governed by a number of factors such as: Technical Economics Politics of Organization Here we will basically discuss Non-technical factors which include the financial status and the support organization of the vendor. In this article, we will concentrate on discussing the economic and organizational factors that a
2 min read
Categories of End Users in DBMS
Pre-Requisite: Different Types of End Users End users are basically those people whose jobs require access to the database for querying, updating, and generating reports. The database primarily exists for their use. There are several categories of end-users these are as follows. Casual End usersNaive or Parametric End UsersApplication ProgrammersSo
3 min read