0% found this document useful (0 votes)
4 views31 pages

DBMS

The document discusses transaction management in database systems, defining a transaction as a logical unit of work that ensures data consistency and integrity through ACID properties: Atomicity, Consistency, Isolation, and Durability. It outlines the phases of a transaction, techniques for managing transactions, and various isolation levels to prevent data inconsistency. Additionally, it covers the importance of transaction management in scenarios like banking, online booking, and e-commerce.

Uploaded by

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

DBMS

The document discusses transaction management in database systems, defining a transaction as a logical unit of work that ensures data consistency and integrity through ACID properties: Atomicity, Consistency, Isolation, and Durability. It outlines the phases of a transaction, techniques for managing transactions, and various isolation levels to prevent data inconsistency. Additionally, it covers the importance of transaction management in scenarios like banking, online booking, and e-commerce.

Uploaded by

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

TRANSACTION MANAGEMENT &

ACID PROPERTIES
TRANSACTION

Definition:
A transaction in database management is a single, logical unit of work that
consists of one or more database operations (such as insert, update, delete,
or retrieve) executed as a single sequence. A transaction is considered
complete only if all operations succeed; if any operation fails, the entire
transaction is rolled back, leaving the database in its original state.

In essence, a transaction is an indivisible set of actions that must either fully


complete or fully fail, ensuring data consistency and integrity within the
database.
TRANSACTION-LOGIC DIAGRAM

plaintext
Copy code
Start Transaction
|
V
Execute Operations
|
Check for Errors (Any operation failed?)
|
+-------------+
| |
Yes | | No
V V
Rollback Commit
(Undo Changes) (Save Changes)
|
V
End Transaction
QUESTION&ANSWERS

1. The process of ensuring that data is accurate, consistent, complete, and valid throughout its
lifecycle
2. What is a sequence of one or more operations performed as a single, logical unit of work, and it
either completes fully or not at all
3.Ticket booking Is example of
4.what is used to save changes
5.what is used to revert changes


data integrity

transaction management

Isolation

Rollback

commit
PHASES OF TRANSACTION
PHASES

Phase 1: Active Phase 2: Partially Committed

Explanation: The transaction is Explanation: The transaction has


performed some operations, but not all.
initiated and begins executing.
SQL Syntax: INSERT INTO
SQL Syntax: BEGIN transaction_log (transaction_id, status)
TRANSACTION; VALUES (1, 'pending');
PHASES

Phase 3: Committed Phase 4: Failed

Explanation: The transaction has Explanation: The transaction


completed successfully. encounters an error.
SQL Syntax: ROLLBACK;
SQL Syntax: COMMIT;
PHASES

Phase 5: Aborted Phase 6: Terminated


Explanation: The transaction Explanation: The transaction is
is explicitly cancelled. completed, either successfully
or unsuccessfully.
SQL Syntax: ROLLBACK;
SQL Syntax: END
TRANSACTION;
PHASES

Example : Hotel booking SQL Code:


BEGIN TRANSACTION;
1. Active: Book room UPDATE rooms SET availability =
availability - 1 WHERE room_id =
2. Partially Committed: 1;
Reserve room INSERT INTO reservation_log
3. Committed: Charge card (reservation_id, status) VALUES
4. Failed: Payment declined (1, 'pending');
5. Aborted: User cancels UPDATE reservations SET status
= 'confirmed' WHERE
reservation reservation_id = 1;
6. Terminated: Reservation COMMIT;
complete END TRANSACTION;
QUESTION & ANSWERS
Question 1: What is the primary purpose of the "Partial Commit" phase in a transaction?
A) To roll back the entire transaction
B) To temporarily save changes
C) To verify user authentication
D) To finalize the transaction
Answer: B) To temporarily save changes
Question 2: Which transaction phase is responsible for reversing all changes made during
the transaction if an error occurs?
A) Active
B) Partially Committed
C) Committed
D) Aborted
Answer: D) Aborted
Question & ANSWERS
Question 3: What is the primary difference between "Failed" and "Aborted" transaction phases?

A) Failed: System error, Aborted: User-initiated cancellation


B) Failed: User error, Aborted: System-initiated cancellation
C) Failed: Transaction completed with errors, Aborted: Transaction cancelled
D) Failed: Transaction pending, Aborted: Transaction rolled back

Question 4: In which transaction phase are all changes permanently saved?

A) Active
B) Partially Committed
C) Committed
D) Terminated
TRANSACTION MANAGEMENT
TECHNIQUES

What is Transaction management technique?


Transaction management techniques are methods used to handle
transactions effectively in database systems and distributed systems.

Why we need this techniques?


They ensure transactions in databse system are executed in a
safe,consistent and isolated manner.
Social media

SCENARIO:
Users interact by liking,commenting or sharing post with changes.

TECHNIQUES USED:
 Multiversion concurrency control(MVCC)
 Deadlock management
 Shadow paging or Write-Ahed logging(WAL)
BANKING SYSTEMS

SCENARIO:
When a user transfer money from one bank account to
another.

TECHNIQUES USED:
 Atomicity
 Isolation
 Consistency
OTHER EXAMPLES

b.Online booking system c.Health care system

a.Ecommerce System

d.Telecommunication system
TYPES OF TECHNIQUES

1.TWO-PHASE COMMIT PROTOCOL:


Phases:

Phase1:prepare phase

Phase2:commit phase
Advantages:
 Consistency
 Realiability
 atomicity
Disadvantages:
 Blocking
 Latency
 complexity
TYPES OF TECHNIQUES

2.Optimistic concurrency control(OCC):



Phase:
 Read phase
 Validation Phase
 Write phase

Advantages:
 performance
 simplicity
 High throughput

Disadvantages:
 Conflicts handling
 Increased retry cost
 Memory consumption
TYPES OF TECHNIQUES

3.Multiversion concurrency control(MVCC):



Advantages:
 Reduced blocking
 Consistent reads
 High concurrency

Disadvantages:
 Storage overhead
 Complexity in versioning
 Potential state data
QUESTIONS&ANSWERS

In the first phase of the Two-Phase Commit Protocol, the coordinator:


A. Rolls back the transaction for all participants
B. Sends a "prepare" request to all participants
C. Commits the transaction immediately
D. Validates data across all nodes
Answer: B. Sends a "prepare" request to all participants
Question 2: Which transaction management technique ensures that multiple transactions can execute
concurrently without conflicts?
A) Locking
B) Timestamping
C) Optimistic concurrency control
D) Pessimistic concurrency control
Answer: C) Optimistic concurrency control
QUESTIONS&ANSWERS

The main purpose of the Two-Phase Commit Protocol (2PC) in distributed transactions is to:
A. Optimize query performance
B. Ensure consistency across multiple systems
C. Improve network speed
D. Minimize disk space usage
Answer: B. Ensure consistency across multiple systems
In the Two-Phase Locking (2PL) protocol, what are the two phases?
A. Read Phase and Write Phase
B. Locking Phase and Unlocking Phase
C. Prepare Phase and commit Phase
D. Request Phase and Release Phase
Answer: C. Prepare Phase and Commit Phase
ACID-Properties

ATOMICITY(A)

CONSISTENCY(C)

ISOLATION(I)

DURABILITY(D)
ATOMICITY
ATOMICTY
ATOMICTY
KEY POINTS

All-or-Nothing Principle: Either all operations in the transaction are


completed, or none are. There is no partial completion.

Rollback Mechanism: If a transaction fails, atomicity ensures that all changes


made during the transaction are undone, restoring the database to its
previous state.

Commit or Abort: A transaction is only considered successful (committed) if all


operations within it succeed. If any operation fails, the transaction is aborted,
and changes are rolled back.
CONSISTENCY

In the case of transactions,the integrity of the data is very
essential so that the database remains consistent before and
after the transaction

The data should always be correct
Breakdown of Consistency
Data Integrity Rules: Consistency ensures that all data follows defined integrity rules, such as
foreign key constraints, primary key constraints, and unique constraints. For example, if a
foreign key references another table, the referenced data must exist for consistency to be
maintained.

State Validation: Before a transaction, the database is in a valid state according to predefined
rules and constraints. After the transaction, the database must still be in a valid state. If a
transaction would violate these rules, it is aborted or rolled back.

Maintaining Business Logic: Consistency also means that business rules are consistently
followed. For instance, if a banking transaction ensures that money can’t be transferred if
funds are insufficient, this rule must always hold.

Error Prevention: Consistent transactions prevent incomplete or erroneous data from being
committed to the database. If a transaction is partially completed or fails, the DBMS should
roll back to the previous consistent state.
QUESTION &ANSWERS

Why is atomicity important in online shopping?


A) It helps to make faster payments.
B) It ensures the items are available for purchase.
C) It prevents orders from being partially completed.
D) It allows for easy returns
If you are making a pizza with multiple toppings, how does atomicity apply?
A) You can only add one topping at a time.
B) You must complete all steps to make the pizza or none at all.
C) You can leave out any topping you want.
D) You can start eating the pizza before it's fully made
QUESTION &ANSWERS

If a database is consistent, what does that mean after a transaction?


a) The database might be messed up
b) The database is in a valid state
c) The database loses all its data
d) The database duplicates all data
Answer: b) The database is in a valid state
Why is consistency important in a database?
a) To keep information in the right order and prevent errors
b) To allow errors in data
c) To make the data unreadable
d) To mix up data
Answer: a) To keep information in the right order and prevent errors
ISOLATION

Definition: Isolation ensures that transactions are executed independently of each other. Even if
multiple transactions are occurring concurrently, each transaction must execute as if it were the only
one. This prevents transactions from interfering with each other and causing data inconsistency.
Levels of Isolation: Database systems provide various isolation levels to balance performance and
consistency. The main isolation levels are:
Read Uncommitted: Allows a transaction to see uncommitted changes from other transactions. Fast
but can lead to dirty reads (inconsistent data).
Read Committed: A transaction can only read committed data, avoiding dirty reads but not non-
repeatable reads (where data read previously might change).
Repeatable Read: Prevents other transactions from modifying data read by a current transaction,
ensuring consistency but can still allow phantom reads.
Serializable: The highest level of isolation, ensuring transactions execute sequentially, but it can be
slower and may lead to more locks or deadlocks.
Isolation is critical for preventing problems like dirty reads, non-repeatable reads, and phantom reads.
DURABILITY

Definition: Durability guarantees that once a transaction is committed, it will


remain so, even in the event of a system failure (like a crash or power loss).
This property ensures that the results of a transaction are permanently
recorded in the database.
Mechanism: Databases use techniques such as logging, write-ahead logging
(WAL), and checkpoints to ensure durability. After a transaction commits,
changes are stored in non-volatile storage (such as disk storage), so the data
remains safe and recoverable even if a system crash occurs.
Together, Isolation and Durability help provide consistency and reliability in
managing transactions in DBMS, especially in multi-user and high-availability
environments.

You might also like