DBMS Unit - 3
DBMS Unit - 3
TRANSACTIONS
TRANSACTION CONCEPTS
Collections of operations (processes) that form
a single logical unit of work are called
transactions.
A transaction includes one or more database
access operations. These can include insertion,
deletion, modification or retrieval operations.
These operations executed between the begin
transaction and end transaction.
read(X), which transfers the data item X from
the database to a local buffer belonging to the
transaction that executed the read operation.
write(X), which transfers the data item X from the local
buffer of the transaction that executed the write back
to the database.
Let's take an example to debit transaction from
an account which consists of following
operations:
R(X);
X = X - 500;
W(X);
Let's assume the value of X before starting of the transaction
is 4000.
The first operation reads X's value from database and stores it
in a buffer.
The second operation will decrease the value of X by 500. So
buffer will contain 3500.
The third operation will write the buffer's value to the
database. So X's final value will be 3500.
But it may be possible that because of the failure of
hardware, software or power, etc. that transaction may fail
before finished all the operations in the set.
For example: If in the above transaction, the debit transaction
fails after executing operation 2 then X's value will remain
4000 in the database which is not acceptable by the bank.
To solve this problem, we have two important operations:
Commit: It is used to save the work done permanently.
Rollback: It is used to undo the work done.
TRANSACTION PROPERTY
The transaction has the four properties. These
are used to maintain consistency in a
database, before and after the transaction.
Property of Transaction
Atomicity
Consistency
Isolation
Durability
ATOMICITY
All operations of the transaction take place at
once if not, the transaction is aborted.
Each transaction is treated as one unit and
either run to completion or is not executed at
all.
Atomicity involves the following two operations:
Active state
The transaction is being executed.
For example: Insertion or deletion or updating a
record is done here. But all the records are still not
saved to the database.
Partially committed
A transaction executes its final operation, but the data
is still not saved to the database.
In the total mark calculation example, a final display of
the total marks step is executed in this state.
Committed
A transaction is said to be in a committed state if it
executes all its operations successfully. In this state, all
the effects are now permanently saved on the database
system.
Failed state
If any of the checks made by the database recovery
system fails, then the transaction is said to be in the
failed state.
In the example of total mark calculation, if the database
is not able to fire a query to fetch the marks, then the
transaction will fail to execute.
ABORTED
If the transaction fails in the middle of the
transaction then before executing the
transaction, all the executed transactions are
rolled back to its consistent state.
After aborting the transaction, the database
recovery module will select one of the two
operations:
Re-start the transaction
Kill the transaction
SCHEDULE
A series of operation from one transaction to
another transaction is known as schedule.
SERIAL SCHEDULE
The serial schedule is a type of schedule where
one transaction is executed completely before
starting another transaction.
NON-SERIAL SCHEDULE
If interleaving of operations is allowed, then
there will be non-serial schedule.
It contains many possible orders in which the
system can execute the individual operations of
the transactions.
SERIALIZABILITY
Serializability is a concurrency scheme where
the concurrent transaction is equivalent to one
that executes the transactions serially.
Types of Serializability
Conflict
Serializability
View Serializability
Conflict Serializability
Conflict serializability defines two instructions of
two different transactions accessing the same
data item to perform a read/write operation.
It deals with detecting the instructions that are
conflicting in any way and specifying the order
in which the instructions should execute in case
there is any conflict.
A conflict serializability arises when one of the
instruction is a write operation.
The following rules are important in Conflict
Serializability
View Conflict
Serializability Serializability