this docoument presents the whole concept about the transation which is a one of the most important topic in data base management system.This helps in understanding the transaction process and the states of transaction
2. 2
Introduction to TRANSACTION
Transactions refer to a set of
operations that are used for
performing a set of logical
work. Usually, a transaction
means the data present in
the DB has changed.
Protecting the user data
from system failures is one
of the primary uses of
DBMS.
3. 3
A user can make different types of requests to
access and modify the contents of a database. So,
we have different types of operations relating to
a transaction.
Operations of transaction
• i) Read(X)
A read operation
is used to read
the value of X
from the
database and
store it in a buffer
in the main
memory for
further actions
such as
displaying that
value.
• ii) Write(X)
A write operation is
used to write the
value to the
database from the
buffer in the main
memory. For a
write operation to
be performed, first
a read operation is
performed to bring
its value in buffer,
and then some
changes are made
to it.
• iii) Commit
Due to some failure of
power, hardware, or
software, etc., a
transaction might get
interrupted before all its
operations are
completed. To ensure
that further operations of
any other transaction
are performed only after
work of the current
transaction is done, a
commit operation is
performed to the
changes made by a
transaction permanently
to the database.
• iv) Rollback
This operation is
performed to
bring the
database to the
last saved state
when any
transaction is
interrupted in
between due to
any power,
hardware, or
software failure.
4. 4
Transaction Schedules
When multiple transaction requests are made at the same time,
we need to decide their order of execution. Thus, a transaction
schedule can be defined as a chronological order of execution of
multiple transactions.
There are broadly two types of transaction schedules
Serial
Schedule
Non-Serial
Schedule
5. 5
i) Serial Schedule
• In this kind of schedule, when multiple transactions are to be executed, they
are executed serially, i.e. At one time only one transaction is executed while
others wait for the execution of the current transaction to be completed.
This ensures consistency in the database as transactions do not execute
simultaneously.
• But, it increases the waiting time of the transactions in the queue, which in
turn lowers the throughput of the system, i.e. Number of transactions
executed per time.
• To improve the throughput of the system, another kind of schedule are used
which has some more strict rules which help the database to remain
consistent even when transactions execute simultaneously.
6. 6
ii) Non-Serial Schedule
To reduce the waiting time of transactions in the waiting queue
and improve the system efficiency, we use non serial schedules
which allow multiple transactions to start before a transaction is
completely executed. This may sometimes result in inconsistency
and errors in database operation.
So, these errors are handled with specific algorithms to maintain
the consistency of the database and improve CPU throughput as
well.
• Non-serial schedules are also sometimes referred to as parallel
schedules, as transactions execute in parallel in these kinds of
schedules.
7. Subject Code
7
TYPES OF TRANSACTIONS
• Read-only Transactions:
• Only retrieves data without making any changes.
• Update Transactions:
• Modifies existing data in the database.
• Insert Transactions:
• Adds new records to the database.
• Delete Transactions:
• Removes data from the database.
• Complex Transactions:
• Includes multiple types of operations in a single transaction.
8. 8
States of transaction
A transaction is a series of operations, so various states
occur in its completion journey.
9. TRANSACTION STATES
• Active:
• The transaction is being executed.
• Partially Committed:
• After the final operation is executed, but before the transaction is committed.
• Committed:
• The transaction has been successfully completed and changes are saved
permanently.
• Failed:
• If any error occurs during execution, the transaction enters this state.
• Aborted:
• The transaction has been rolled back due to an error, and the database is restored
to its previous state.
10. 10
Properties of transaction
As transactions deal with
accessing and modifying the
contents of the database, they
must have some basic properties
which help maintain the
consistency and integrity of the
database before and after the
transaction. Transactions follow 4
properties, namely, Atomicity,
Consistency, Isolation, and
Durability.
Generally, these are referred to as
ACID properties of transactions in
DBMS.
ATOMICITY
This property ensures
that either all
operations of a
transaction are
executed or it is
aborted. In any
case, a transaction
can never be
completed partially.
CONSISTENCY
This property of a
transaction keeps
the database
consistent before
and after a
transaction is
completed.
ISOLATION
This property states that two
transactions must not
interfere with each other, i.e.
If some data is used by a
transaction for its execution,
then any other transaction
can not concurrently
access that data until the
first transaction has
completed.
DURABILITY
This property
ensures that the
changes made to
the database after
a transaction is
completely
executed, are
durable.
11. Subject Code
11
CONCURRENCY CONTROL
• Concurrency control ensures that multiple transactions can execute
in parallel without conflicting with each other.
• Techniques include:
• Locking: Locks data to prevent other transactions from accessing it
simultaneously.
• Timestamp Ordering: Assigns timestamps to transactions and processes
them in timestamp order.
• Optimistic Concurrency Control: Allows transactions to execute without
restrictions and checks for conflicts at commit time.
12. Subject Code
12
TRANSACTION RECOVERY
• Recovery ensures that the database is restored to a
consistent state after a failure (e.g., power loss, system crash).
• Techniques:
• Rollback: If a transaction fails, it is rolled back to its original state.
• Write-Ahead Logging (WAL): Logs are written to disk before the
actual transaction data is committed to ensure recovery.
• Shadow Paging: Uses a backup copy of the database pages to
roll back if necessary
13. 13
Conclusion
Transactions in DBMS are pivotal in maintaining the
integrity and consistency of the database through a
series of well-defined operations and states. From the
initial execution of operations to handling errors and
ensuring consistency, transactions must adhere to the
ACID properties—Atomicity, Consistency, Isolation,
and Durability. These properties guarantee that
transactions are processed reliably and that the
database remains stable even in the face of failures or
concurrent operations.