A transaction is a logical unit of database work that should either complete correctly as a whole or leave the database in a safe state. The four ACID properties are Atomicity, Consistency, Isolation and Durability. Together, they help a DBMS protect data during operations such as bank transfers, ticket booking, online payments and order placement. This chapter explains transactions from zero, including READ and WRITE operations, COMMIT, ROLLBACK, SAVEPOINT, transaction states, failures and real-life examples.
What Is a Transaction in DBMS?
A transaction is a sequence of one or more database operations treated as one logical unit of work. It should finish completely or be undone safely if something goes wrong.
Think of an online bank transfer of Rs 500 from Asha to Ravi. The database must reduce Asha's balance and increase Ravi's balance. These two changes belong to one logical transaction.
Memory line
Transaction = one complete logical jobIf you need SQL command basics first, revise SQL Basics in DBMS. For data-validity rules, revise Integrity Constraints in DBMS.
Why Does a DBMS Need Transactions?
Without transactions, a system could leave half-finished work in the database. That is dangerous because users usually expect one business action to behave like one unit.
The DBMS uses transactions so that failures, concurrent users and system crashes do not easily leave the database in an inconsistent state.
Basic Transaction Operations: READ and WRITE
In DBMS theory, a transaction is often shown with simple read and write operations.
read(X)
X = X - 500
write(X)
read(Y)
Y = Y + 500
write(Y)
Here X may represent Asha's balance and Y Ravi's balance.
READ(X)
Copies the current value of database item X into the transaction's local working area.
WRITE(X)
Writes the transaction's changed value of X back to the database.
Actual DBMSs hide many internal details, but this notation is useful for understanding schedules, concurrency control and recovery.
What Are ACID Properties?
ACID stands for Atomicity, Consistency, Isolation and Durability. These are the four main reliability properties expected from database transactions.
All operations of a transaction happen, or none of them are kept.
A successful transaction should move the database from one valid state to another valid state.
Concurrent transactions should not interfere in a way that breaks the required correctness guarantees.
Once a transaction is committed, its effects should survive later failures such as a crash.
Atomicity Explained With a Bank Transfer
Suppose Asha sends Rs 500 to Ravi.
Step 1: Asha balance - 500
Step 2: Ravi balance + 500
Imagine the server crashes after Step 1 but before Step 2. If the first change remained permanent, money would disappear from the system.
Atomicity prevents this half-completed result. The DBMS should either complete both steps or undo the incomplete transaction.
Atomicity shortcut
All operations or zero operationsConsistency Explained Simply
Consistency means a transaction should respect the database's rules, constraints and application invariants.
Suppose the total money before transfer is:
Asha = Rs 5,000
Ravi = Rs 3,000
Total = Rs 8,000
After transferring Rs 500:
Asha = Rs 4,500
Ravi = Rs 3,500
Total = Rs 8,000
The transaction changed individual balances but did not create or destroy money in this simple example.
Consistency does not mean every database automatically knows every business rule. The rules must be represented through constraints, correct transaction logic and other controls. The DBMS then helps enforce them.
Isolation Explained With Two Users
Suppose two people try to use the same account at nearly the same time. One transaction is withdrawing money while another transaction is checking or changing the same balance.
If the operations are mixed carelessly, one transaction may see incomplete changes from another transaction or overwrite another update.
Poor isolation
One transaction can observe or interfere with another transaction's intermediate work in an unsafe way.
Proper isolation
The DBMS controls concurrent execution so the result satisfies the chosen isolation guarantees.
Isolation is closely connected to schedules, serializability, locks, timestamps and isolation levels. Those are usually studied in the next concurrency-control chapter.
Durability Explained With a Power Failure
Suppose a transaction is committed and the user sees “Payment successful.” One second later, the database server loses power.
Durability means the committed result should not simply disappear after the crash.
DBMSs commonly use recovery techniques such as logs and stable storage mechanisms so committed work can be preserved or recovered.
Durability shortcut
COMMIT means the result should survive later failuresBank Transfer Transaction Simulator
Assume Asha has Rs 5,000 and Ravi has Rs 3,000. The transaction transfers Rs 500.
Successful transfer
What should happen?
COMMIT, ROLLBACK and SAVEPOINT
Example
START TRANSACTION;
UPDATE accounts
SET balance = balance - 500
WHERE account_id = 101;
SAVEPOINT after_debit;
UPDATE accounts
SET balance = balance + 500
WHERE account_id = 202;
COMMIT;
If a later step fails and the DBMS supports the required behavior, a rollback can undo the uncommitted work. Exact syntax differs across MySQL, PostgreSQL, Oracle and SQL Server.
COMMIT vs ROLLBACK
| Point | COMMIT | ROLLBACK |
|---|---|---|
| Main purpose | Confirm successful transaction changes | Undo uncommitted transaction changes |
| Effect | Changes become durable according to DBMS guarantees | Database returns to an earlier safe transaction state |
| Used when | All required steps succeed | A failure, validation problem or cancellation occurs |
| ACID connection | Supports durability | Supports atomicity |
Transaction States in DBMS
A transaction moves through different states from start to finish. Textbooks may show slightly different diagrams, but these are the common states.
Transaction State Flow Explained Step by Step
Simple SQL Transaction Example
START TRANSACTION;
UPDATE accounts
SET balance = balance - 500
WHERE account_id = 101;
UPDATE accounts
SET balance = balance + 500
WHERE account_id = 202;
COMMIT;
If validation fails before commit, the application may execute:
ROLLBACK;
Transaction-start syntax, autocommit behavior and DDL transaction behavior vary across DBMS products. Always follow the documentation of the system you are actually using.
What Is Autocommit?
In many DBMS tools and configurations, individual statements may be committed automatically unless an explicit transaction is started or autocommit is disabled.
Autocommit on
Each eligible statement may be treated as its own transaction and committed automatically.
Explicit transaction
Multiple statements are grouped so the application decides when to COMMIT or ROLLBACK.
This matters because a multi-step business action such as a money transfer normally needs all related statements inside one controlled transaction.
Common Transaction Failures
Real-Life Examples of ACID Properties
| Situation | ACID property | What it means |
|---|---|---|
| Bank transfer | Atomicity | Debit and credit should succeed together or be undone. |
| Inventory never becomes invalid | Consistency | Rules and constraints remain satisfied. |
| Two users book at the same time | Isolation | Concurrent transactions should not corrupt each other's results. |
| Payment survives server restart | Durability | A committed result remains after failure. |
How COMMIT, ROLLBACK and Recovery Connect to ACID
ACID properties are goals. The DBMS uses several techniques such as logging, locking, timestamps, MVCC and recovery procedures to provide them.
Transaction vs SQL Statement
SQL Statement
One command such as UPDATE, INSERT or DELETE.
Transaction
One logical unit that may contain one statement or many statements.
Example: one bank transfer transaction may contain two UPDATE statements plus validation queries.
Consistency vs Isolation
Consistency
Focuses on valid database rules and invariants before and after a successful transaction.
Isolation
Focuses on safe interaction between transactions running at the same time.
A database can have good constraints but still need isolation controls when many users access the same data concurrently.
What Happens When Many Transactions Run Together?
Real databases run many transactions concurrently because processing them strictly one by one would reduce performance.
Concurrency creates new problems such as:
These are handled through isolation levels and concurrency-control methods. That should be the next chapter after transactions.
How Transactions Connect to Constraints, SQL and Database Design
Transactions do not work in isolation from the rest of DBMS theory.
Revise Normalization in DBMS if you want to connect transaction correctness with clean table design.
Transactions and ACID Mistakes to Avoid
How to Write Transactions and ACID in Semester Exams
Definition
Define a transaction and write the full form of ACID.
Explain ACID
Write one or two lines for Atomicity, Consistency, Isolation and Durability with a bank example.
Full answer
Add transaction states, COMMIT, ROLLBACK, SAVEPOINT, failure handling and a complete bank-transfer example.
For better presentation, use How to Write High-Scoring Answers in University Semester Exams.
Practice Questions With Answers
1. What is a transaction in DBMS?
A transaction is a sequence of database operations treated as one logical unit of work.
2. What does ACID stand for?
Atomicity, Consistency, Isolation and Durability.
3. What is atomicity?
Atomicity means all operations of a transaction are completed successfully or the incomplete transaction is undone.
4. What is consistency?
Consistency means a successful transaction leaves the database in a state that satisfies the required rules and constraints.
5. What is isolation?
Isolation controls how concurrent transactions interact so they do not produce unacceptable interference.
6. What is durability?
Durability means committed transaction effects survive later failures such as a crash.
7. What is the difference between COMMIT and ROLLBACK?
COMMIT confirms successful changes, while ROLLBACK undoes uncommitted transaction work according to DBMS rules.
8. What is a SAVEPOINT?
A SAVEPOINT marks an intermediate point inside a transaction so partial rollback may be possible.
9. What are the main transaction states?
Common states are Active, Partially Committed, Committed, Failed, Aborted and Terminated.
10. What should I study after transactions and ACID?
Study schedules, serializability, concurrency problems, locking protocols, deadlocks, timestamps and recovery.
Transactions and ACID One-Minute Revision Sheet
Ultimate memory line
Transaction = complete job · ACID = rules that keep that job safeFrequently Asked Questions
What is a transaction in DBMS in simple words?
A transaction is one complete logical database job, such as transferring money, placing an order or booking a ticket.
What are the ACID properties of a transaction?
The ACID properties are Atomicity, Consistency, Isolation and Durability.
What is atomicity with a real-life example?
In a bank transfer, debit and credit should both happen. If one step fails, the incomplete transfer should be undone.
What is the difference between COMMIT and ROLLBACK?
COMMIT makes successful transaction changes permanent, while ROLLBACK cancels uncommitted changes according to the DBMS transaction rules.
What are transaction states in DBMS?
Common transaction states are Active, Partially Committed, Committed, Failed, Aborted and Terminated.
What should I learn after ACID properties?
Continue with schedules, serializability, concurrency control, locking protocols, deadlocks and recovery techniques.
What Should You Learn Next?
Next: Schedules, Serializability & Concurrency Problems
You now understand what a transaction is and what ACID is trying to guarantee. The next step is learning how multiple transactions execute together, including serial and concurrent schedules, conflict serializability, view serializability, dirty reads, lost updates and recoverable schedules.
For video revision after reading, use the DBMS YouTube study guide only as a secondary resource.
