0% found this document useful (0 votes)
7 views4 pages

Transaction

The document discusses transactions in databases, defining them as a set of logically linked operations, and outlines their states: active, partially committed, committed, failed, and aborted. It emphasizes the ACID properties of transactions—Atomicity, Consistency, Isolation, and Durability—which ensure the integrity and reliability of database operations. Examples illustrate how transactions function and the importance of maintaining consistent states throughout the process.

Uploaded by

wiwim82755
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Transaction

The document discusses transactions in databases, defining them as a set of logically linked operations, and outlines their states: active, partially committed, committed, failed, and aborted. It emphasizes the ACID properties of transactions—Atomicity, Consistency, Isolation, and Durability—which ensure the integrity and reliability of database operations. Examples illustrate how transactions function and the importance of maintaining consistent states throughout the process.

Uploaded by

wiwim82755
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Content

• Transaction
• States of Transaction
• Properties of Transaction
• Importance of Transaction Properties
Transaction
A transaction is a set of logically linked operation. Therefore, it includes a collection of related
tasks.
 It can be thought of as a database action or sequence of actions.
Example:
 Suppose there are two friends, say, Nonte and Fonte. Nonte make a bank transfer of Rs 500
to Fonte's account on Fonte’s birthday.
 This transfer should have a sequence of tasks.

Illustration: How transfer is made


Nonte's Account
Open_Account (Nonte)
Old_Balance = [Link] ---- Say Nonte has Rs 2000 in account
New_Balance = Old_Balance - 500 - New balance of Nonte will Rs 1500
[Link] = New_Balance
Close_Account(Nonte)
Fonte's Account
Open_Account (Fonte)
Old_Balance = [Link]  Say Fonte has Rs 1000/- initially
New_Balance = Old_Balance + 500  Fonte now have Rs 1500/-
[Link] = New_Balance
Close_Account(Fonte)
Basic Operations
Following are the main operations of transaction:
• Read(X): Read operation is used to read the value of X from the database and stores it in
a buffer in main memory.
• Write(X): Write operation is used to write the value back to the database from the buffer.

1|Page
States of Transaction
Active state
• The active state is the first state of each transaction. Here, the transaction start executed.
• E.g., Insertion or deletion or updating a record performed here. However, the records are
yet to be saved to the database.
Partially committed
• In this state, a transaction executes its final operation. However, the data is not saved to
the database.
• E.g., in calculating the total, a simple display of the total marks executed in this state.
Committed
• When all database operations executed and all the effects of these database operations are
now permanently saved on the database system, then A transaction is said to be in a
committed state.
Failed state
Whenever the checks induced by the database recovery system fails, then the transaction is said
to be in the failed state.
E.g., if the database is not able to perform a query to fetch the marks, then the transaction fails to
execute and said to be in failed state.
Aborted
• If any of the checks fail and the transaction has reached a failed state, then the database
recovery system tries to make sure that the database stays in the previous consistent state.
Otherwise, it aborts or roll back the transaction to make the database remain in a
consistent state.
• If the transaction fails in the middle, then before the final execution of the transaction, all
the executed transactions are rolled back to its consistent state.
• After aborting the transaction, the database recovery mechanism will perform either of
the following operations:
a) Re-start the transaction
b) Kill the transaction

2|Page
State Diagram of Transaction
A database, the transaction can be in one of the following states

PROPERTIES OF TRANSACTION
ACID Properties of Transaction
– A: Atomicity
– C: Consistency
– I: Isolation
– D: Durability
Atomicity
• It says that all operations of the transaction take place at once; if not, the
transaction is canceled, i.e., aborted.
o There is no midway, i.e., the transaction cannot occur partially. Each transaction
is treated as one unit, and either has to be performed or is not executed at all.
Example of Atomicity
Example: Let's assume that following transaction T consisting of T1 and T2. A consists of Rs.
500 and B consists of Rs. 200. Transfer Rs. 100 from account A to account B.
T1 T2
Read(A) Read(B)
A:= A-100 B:= B+100
Write(A) Write(B)
After Completion of the Transaction
– A should have Rs 400
– B should have Rs 300

3|Page
If the transaction T fails after the completion of transaction T1, but before the end of transaction
T2, then the amount will be subtracted from A without being added to B.
 This results in an inconsistent database state.
 To ensure the correctness of the database state,
– The transaction must be executed in totality or should not be performed at all.
Consistency
It refers to the correctness of a database. The integrity constraints are maintained so that
the database is consistent before and after the transaction. To achieve the following:
• The execution of a transaction will leave a database in either its former stable state or a
new steady state.
• The consistent property of the database states that every transaction should perceive a
consistent database instance.
• The transaction should be used to take the database from one consistent state to another
consistent state.
For example: Considering previous example, the total amount must be maintained before or
after the transaction.
Total amount before T occurs: 500 (In A) +200 (In B) =700
Total amount after T occurs: 400 (In A) + 300 (In B) =700
Isolation
It implies that the data used at the time of execution of a transaction cannot be used by a
second transaction until and unless the first transaction is performed.
For example:
 In isolation, if the transaction T1 is being executed and using the data say D, then any
other transaction say, T2, can't access the data D until the transaction T1 finish.
 The concurrency control mechanism of the DBMS supports the isolation property.
Durability
The durability property is the performance indicator of a database's consistent state. It
guarantees that the transaction should made permanent changes in the database.
 When a transaction is completed, then the database reaches a state referred to as the
consistent state. A consistent state of the database cannot be lost, even in the event of a
system's failure.
 The backup and recovery mechanism of the DBMS enforces the Durability property.

4|Page

You might also like