A transaction is an action or series of actions that are being performed by a single user or application program, which reads or updates the contents of the database.
A transaction can be defined as a logical unit of work on the database. This may be an entire program, a piece of a program, or a single command (like the SQL commands such as INSERT or UPDATE), and it may engage in any number of operations on the database. In the database context, the execution of an application program can be thought of as one or more transactions with non-database processing taking place in between.
EXAMPLE-
A simple example of a transaction will be dealing with the bank accounts of two users, let say Karlos and Ray. A simple transaction of moving an amount of 5000 from Karlos to Ray engages many low-level jobs. As the amount of Rs. 5000 gets transferred from the Karlos's account to Ray's account, a series of tasks gets performed in the background of the screen.
This straightforward and small transaction includes several steps: decrease Karlos's bank account from 5000:
Open_Acc (Karlos) OldBal = Karlos.bal NewBal = OldBal - 5000 Ram.bal = NewBal CloseAccount(Karlos)
You can say, the transaction involves many tasks, such as opening the account of Karlos, reading the old balance, decreasing the specific amount of 5000 from that account, saving new balance to an account of Karlos, and finally closing the transaction session.
For adding amount 5000 in Ray's account, the same sort of tasks needs to be done:
OpenAccount(Ray) Old_Bal = Ray.bal NewBal = OldBal + 1000 Ahmed.bal = NewBal CloseAccount(B)