2. WHAT IS TRANSACTION?
A transaction is a set of changes that must all be
made together.
Collection of operations that form a single logical
unit of work are called TRANSACTIONS.
A database system must ensure proper execution
of transactions deplete failures.
It must manage concurrent execution of
transactions to avoid inconsistency.
3. A transaction is a unit of program execution that accesses
and possibly updates various data items. A program
contains statements of the form begin transaction and
end transaction. The transactions consists of all
operations executed between the begin transaction and
end transaction.
Database in
consistent state
Database in
consistent state
Begin
transaction
End
transaction
Execution of transaction
(In between its execution, database may be
in inconsistent state)
4. TRNSACTION CONCEPT
A transaction accesses data with a series of Read
and Write operations.
Read operation : Reading of a database object
means that it is, firstly, brought into main memory
from the disk and then its value is copied into a
program variable i.e.,
Disk to
Main memory Program Variableto
5. Similarly, during write operation, copy of the object is
first modified and then written to disk.
Program Variable
to
Main memory Diskto
Example: Let T be a transaction that transfers $50 from account A
to account B. This transaction can be defined as:
T : read(A)
A:=A-50
write(A)
read(B)
B:=B+50
write(B)
6. PROPERTIES OF TRANSACTION
There are four important properties of transaction(ACID):
Atomicity : A transaction is said to be atomic if a
transaction always executes all of its action in one step
or not execute any actions at all.
It implies that either all or none of the transaction’s
operations are performed.
7. Consistency : A transaction must preserve the
consistency of a database after its execution. It means
that the execution of a transaction must leave a
database in either its prior stable state or new stable
state.
If a transaction fails then the database must be
returned to its previous state.
If it is successful then the database must reflect new
changes.
8. Isolation : It means that the data used during the
execution of a transaction cannot be used by a second
transaction until the first one is completed.
The transactions do not interfere with each other. They
must behave as if they are executed in isolation.
This isolation property of a transaction is used in
multiuser database environments.
9. Durability : The effect of a completed or
committed transaction should persist even after
a system’s failure (crash).
It means that once a transaction commits, the
system must guarantee that result of its
operations will never be lost.
It is the responsibility of the recovery subsystem
of DBMS.
10. S.No. Property Meaning
1. Atomicity All or nothing
2. Consistency No violation of integrity
constraints
3. Isolation Concurrent changes invisible
4. Durability Committed update persist.
So, we can say that:
11. STATES OF TRANSACTION
A transaction can be in various states as shown below in
figure.
Transaction state diagram.
12. Active state: It is the initial state. The transaction stays
in this state while it is executing.
Partially committed state: When the final statement
has been executed, we say, transaction is in partially
committed state.
Failed state: When the normal execution can no longer
proceed, we say that the transaction is in a failed state.
Aborted state: A transaction is aborted if the
transaction has been rolled back and the database has
been restored to its state prior to the start of the
transaction.
Committed state: When a transaction has successfully
been completed.
13. Explanation:- A transaction starts in the active state.
When it finishes its last statement, it enters the
partially committed state. At this time, the
transaction has completed its execution but it is still
possible that it may have to be aborted as the actual
output may still be temporarily residing in the main
memory. DBMS then writes information to disk that
even if the system failure occurs, the update
performed by T can be recreated when the final or last
of this information is written out, the transaction
enters the committed state.