GATE CSEIT/Database/ Transaction in Database ( With basic introduction).
GATE CSEIT/Database/. Transaction in Database ( With basic introduction).
Contents [hide]
- 0.1 Transaction in Database Management System (DBMS)
- 0.2 GATE CSEIT/Database/ Transaction in Database ( With basic introduction).
- 0.3 Institute of Engineering Studies (IES, Bangalore)
- 0.4 Database Management Systems Lecture Notes
- 0.5 Chapter 17: Transactions
- 1
What is a Transaction in a Database?
- 2
Basic Properties of Transactions – ACID
- 3
Transaction States
- 4
Example Transaction (SQL)
- 5
COMMIT and ROLLBACK
- 6
Concurrency Issues in Transactions
- 7
For GATE – Key Concepts to Remember:
- 8
GATE-Level MCQ Example:
Transaction in Database Management System (DBMS)
Introduction to Transactions
A transaction in a Database Management System (DBMS) is a sequence of one or more database operations that are executed as a single logical unit of work. Transactions are used to maintain data integrity, consistency, and reliability in a database.
For example, in a banking system, transferring money from one account to another involves multiple operations:
-
Deducting money from Account A.
-
Adding money to Account B.
If any of these operations fail, the entire transaction must be rolled back to maintain consistency.
Properties of Transactions (ACID Properties)
Transactions in a database follow ACID properties:
-
Atomicity – A transaction is either fully completed or fully rolled back.
-
Consistency – The database remains in a valid state before and after the transaction.
-
Isolation – Transactions are executed independently without interfering with each other.
-
Durability – Once a transaction is committed, the changes are permanent, even if a system failure occurs.
States of a Transaction
A transaction goes through different states during execution:
-
Active – The transaction starts execution.
-
Partially Committed – All operations are performed, but changes are not yet saved.
-
Committed – Changes are permanently stored in the database.
-
Failed – Transaction execution is interrupted due to an error.
-
Aborted – Transaction is rolled back to maintain consistency.
Types of Transactions
-
Read-Only Transaction – Retrieves data without modifying it.
-
Read-Write Transaction – Reads data, modifies it, and stores the changes.
Transaction Control Commands in SQL
-
COMMIT – Saves all changes made by a transaction permanently.
-
ROLLBACK – Undoes all changes made by a transaction.
-
SAVEPOINT – Creates a checkpoint within a transaction to rollback to a specific point.
-
SET TRANSACTION – Defines the properties of a transaction (e.g., isolation level).
Conclusion
Transactions play a crucial role in maintaining database integrity and consistency. By following ACID properties and using transaction control commands, databases ensure that operations are reliable and error-free.
GATE CSEIT/Database/ Transaction in Database ( With basic introduction).
Institute of Engineering Studies (IES, Bangalore)
Database Management Systems Lecture Notes
Chapter 17: Transactions
Here’s a simple and complete introduction to Transactions in Databases, ideal for GATE CSE/IT preparation under the Database Management Systems (DBMS) subject.
What is a Transaction in a Database?
Definition:
A transaction is a sequence of one or more SQL operations that perform a single logical unit of work in a database.
Example: Transferring money from Account A to Account B involves:
Deducting amount from A
Adding amount to B
→ These two must happen together or not at all — that’s a transaction.
Basic Properties of Transactions – ACID
Property | Meaning |
---|---|
A – Atomicity | All operations in a transaction are performed or none at all. |
C – Consistency | Transaction takes the database from one valid state to another. |
I – Isolation | Concurrent transactions should not interfere with each other. |
D – Durability | Once committed, changes are permanent even if the system crashes. |
Transaction States
-
Active – Transaction is being executed.
-
Partially Committed – Last statement is executed.
-
Committed – Changes are saved permanently.
-
Failed – Some error occurred.
-
Aborted – Changes are rolled back.
Example Transaction (SQL)
Either both updates succeed and commit, or they both rollback.
COMMIT and ROLLBACK
-
COMMIT: Saves changes to the database.
-
ROLLBACK: Undoes changes made in the current transaction.
Concurrency Issues in Transactions
When multiple transactions run at the same time, problems can occur:
Issue | Meaning |
---|---|
Lost Update | Two transactions overwrite each other’s update. |
Dirty Read | Reading uncommitted changes from another transaction. |
Non-repeatable Read | Same read gives different values within a transaction. |
Phantom Read | New rows appear during repeated reads. |
These are handled by concurrency control techniques.
For GATE – Key Concepts to Remember:
-
ACID properties
-
Transaction States
-
Schedule types (serial, serializable, conflict serializable)
-
Concurrency issues and solutions (locks, timestamps)
-
Recoverability (undo/redo logs)
GATE-Level MCQ Example:
Q: Which of the following ensures Atomicity in a DBMS?
A. Locking
B. Write-ahead logging
C. Checkpoints
D. Deadlock prevention
Answer: B. Write-ahead logging
Let me know if you want:
-
Notes PDF
-
Practice MCQs
-
Detailed video recommendations
-
Serializability examples or concurrency control algorithms