0% found this document useful (0 votes)
10 views10 pages

DB Presentation Final

this contain information about transaction, conconcurrency and resource locking

Uploaded by

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

DB Presentation Final

this contain information about transaction, conconcurrency and resource locking

Uploaded by

Huriza Tahir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

TRANSACTION,

CONCURRENCY
&
Resource Locking
Presented by: Huriza, Saifa, Anmol

Presented to:
Dr. Muhammad Saleem Kalru
TRANSACTION
 A transaction is a logical unit of work in a database, consisting of one or more
operations that must be completed together to keep the database consistent. It must
either fully complete or entirely fail.

 A transaction generally represent change in database.

Let’s see an Example:

Selling an Item:
In a database, stock information includes a sold list and item quantity.
When an item is sold, it must be added to the sold list and its quantity
subtracted from stock. Both steps need to be completed together to
avoid errors. If either step fails, the transaction entirely fails.
2
Operations of transaction:
Two main operations of Transaction:
 Read:
Accesses data from the database without changing it. This operation allows you to
view or use existing information.
 Write:
Updates data in the database. This operation changes the data, records new
information. ensuring that the database reflects these updates.

Commit & Rollback:


Commit: A transaction is committed if it completes successfully and permanently changes the data.
Rollback: If transaction fails, it is rolled back, all changes made during the transaction are undone, leaving
the data unchanged.

3
Properties of Transaction (ACID properties):
o Atomicity:
Ensures that a transaction is fully completed or not done at all. It's an "all or nothing" rule.

o Consistency:
Consistency guarantees that changes made within a transaction are consistent with
database constrains.

o Isolation:
It insures that multiple transactions access the same data without interfering with each other .
o Durability:
Once a transaction is successfully completed, its changes are permanent and saved even if there is a
system failure.

4
CONCURRENCY:
 Multiple transactions happening in a database at the same time.

 Concurrency is a situation where two or more users access the same piece
of data at the same time. This is common in multi-user environments.
However, concurrent access can sometimes lead to serious problems, such
as data inconsistencies or conflicts.

6
Concurrency
Problems:
1. Lost Update Problem(W-W PROBLEM):
- Occurs when multiple transactions update the same data simultaneously, and the last update overwrites the
others, resulting in data loss.
Example: T1 T2
A=100
R(A)
A=A-50
=50
R(A)
A=A+100
=200

W(A)
W(A)

2. Uncommitted Dependency Problem (Dirty Read):


- Happens when a transaction reads data that is being updated by another transaction that hasn't committed
yet. If the updating transaction rolls back, the read data becomes invalid.

7
T1 T2
Example:
A=10 R(A)

0 A=A+50

W(A)

R(A)
ROLLBACK
FAIL

3. Inconsistent Analysis Problem (Non-Repeatable Read):


- Arises when a transaction reads data multiple times, and another transaction updates some of the
data between reads, causing the first transaction to see different data at different times.
T1 T2
Example:
R(A)
A=100
A=100 R(A)
8
A=A+100
A=200

W(A)

R(A)
A=200
Resource Locking:

Resource locking in databases ensures that only one user can


access shared data at a time, preventing concurrency problems.

Example:
- User 1: Locks the item, retrieves it, reduces the value by 10,
updates
it, and unlocks it.

-User 2: Waits until User 1 is done, then locks the item,


retrieves it, reduces the value by 20, updates it, and unlocks it.

-The final value is 70, ensuring data consistency.

9
Lock
Terminology:
Implicit Lock: Automatically placed by the DBMS.
Explicit Lock: Placed by an application command.
Exclusive Lock: Prevents any access; no other user can read or
change the data.
Shared Lock: Allows reading but prevents changes.
Lock Granularity: The level at which a lock is applied (e.g.,
database, table, row.

These locks ensure proper management of concurrent access


and maintain data integrity.

10
Thank You 

You might also like