GATE CSEIT/Database/ Transaction in Database ( With basic introduction).

GATE CSEIT/Database/. Transaction in Database ( With basic introduction).

play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00

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:

  1. Deducting money from Account A.

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

  1. Atomicity – A transaction is either fully completed or fully rolled back.

  2. Consistency – The database remains in a valid state before and after the transaction.

  3. Isolation – Transactions are executed independently without interfering with each other.

  4. 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:

  1. Active – The transaction starts execution.

  2. Partially Committed – All operations are performed, but changes are not yet saved.

  3. Committed – Changes are permanently stored in the database.

  4. Failed – Transaction execution is interrupted due to an error.

  5. Aborted – Transaction is rolled back to maintain consistency.

Types of Transactions

  1. Read-Only Transaction – Retrieves data without modifying it.

  2. Read-Write Transaction – Reads data, modifies it, and stores the changes.

Transaction Control Commands in SQL

  1. COMMIT – Saves all changes made by a transaction permanently.

  2. ROLLBACK – Undoes all changes made by a transaction.

  3. SAVEPOINT – Creates a checkpoint within a transaction to rollback to a specific point.

  4. 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:

  1. Deducting amount from A

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

  1. Active – Transaction is being executed.

  2. Partially Committed – Last statement is executed.

  3. Committed – Changes are saved permanently.

  4. Failed – Some error occurred.

  5. Aborted – Changes are rolled back.


🧪 Example Transaction (SQL)

sql
BEGIN;

UPDATE accounts SET balance = balance - 500 WHERE id = 'A';
UPDATE accounts SET balance = balance + 500 WHERE id = 'B';

COMMIT;

✅ 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 🔁

GATE CSEIT/Database/ Transaction in Database ( With basic introduction).

INTRODUCTION TO DBMS – Bhubaneswar



Leave a Reply

Your email address will not be published. Required fields are marked *

error: