A transaction is a collection of operations that performs a single logical function in a database application. Each transaction is a unit of both atomicity and consistency. Thus, we require that transactions do not violate any database consistency constraints.
Example: Let's say your account is A and your friend's account is B, and you are transferring 10,000 from A to B. The set of operations or the steps of the transaction are:
1. Read your account balance: R(A);
2. Deduct the amount from your balance: A=A−10,000;
3. Write the remaining balance to your account: W(A);
4. Read your friend's account balance: R(B);
5. Add the amount to his account balance: B=B+10,000;
6. Write the new updated balance to his account: W(B);
This whole set of operations can be called a transaction. R is Read, and W is Write.
The transaction-management component ensures that the database remains in a consistent (correct) state despite system failures (e.g., power failures and operating system crashes) and transaction failures.
The concurrency-control manager controls the interaction among concurrent transactions to ensure the consistency of the database.
In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties.