0% found this document useful (0 votes)
20 views19 pages

DBMS

Database transaction management ensures data consistency and integrity through the execution of transactions, characterized by ACID properties: Atomicity, Consistency, Isolation, and Durability. Schedules dictate the order of operations in transactions, with serial schedules executing transactions sequentially to maintain consistency. Concurrency control mechanisms, including locking methods and timestamp protocols, are essential to prevent issues like deadlocks and ensure efficient resource utilization in multi-user environments.

Uploaded by

Payal Amup
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)
20 views19 pages

DBMS

Database transaction management ensures data consistency and integrity through the execution of transactions, characterized by ACID properties: Atomicity, Consistency, Isolation, and Durability. Schedules dictate the order of operations in transactions, with serial schedules executing transactions sequentially to maintain consistency. Concurrency control mechanisms, including locking methods and timestamp protocols, are essential to prevent issues like deadlocks and ensure efficient resource utilization in multi-user environments.

Uploaded by

Payal Amup
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
You are on page 1/ 19

MAY -23

Q3 (a): What is database transaction management? List properties of a


transaction. [5]
Database Transaction Management:
Transaction management ensures that a database remains in a consistent state, even in
the event of failures or concurrent access. A transaction is a unit of work performed
within a database that must be completed entirely or not at all. It ensures the integrity
and consistency of data by managing the execution of transactions.
Properties of a Transaction (ACID):
1. Atomicity: Ensures that a transaction is treated as a single, indivisible unit.
Either all operations within the transaction are completed, or none are.
2. Consistency: Ensures that a transaction takes the database from one consistent
state to another consistent state.
3. Isolation: Ensures that concurrent transactions do not interfere with each other.
Transactions appear to be executed in isolation.
4. Durability: Ensures that once a transaction is committed, its changes are
permanently stored in the database, even in case of a system failure.

Q3 (b): In database transaction management, what is the role of a


schedule? Explain serial schedule in detail. [6]
Role of Schedule:A schedule determines the order in which operations (read, write,
commit, etc.) from multiple transactions are executed. The goal is to ensure that the
outcome is correct, consistent, and equivalent to some serial execution of the
transactions.
Serial Schedule:
A serial schedule is a type of schedule where transactions are executed one after the
other without any overlap. This ensures that no transaction interferes with another. The
result of a serial schedule is guaranteed to maintain the database's consistency.
Example of Serial Schedule:Consider two transactions, T1 and T2:
• T1: Read(A), A = A + 10, Write(A)
• T2: Read(B), B = B × 2, Write(B)
Serial Execution:
1. Execute all operations of T1: Read(A), A = A + 10, Write(A)
2. Execute all operations of T2: Read(B), B = B × 2, Write(B)
This guarantees correctness but may not utilize resources efficiently in a multi-user
system.
Q3 (c): In serializability, explain conflict and view with examples. [6]
Conflict Serializability :A schedule is conflict-serializable if it can be transformed into a
serial schedule by swapping non-conflicting operations.
Conflict: Two operations conflict if:They belong to different transactions.They access
the same data item.At least one of them is a write operation.
Example: T1: Read(A), Write(A) T2: Read(A), Write(A)
If operations from T1 and T2 are interleaved as:T1: Read(A) T2: Read(A)
T1: Write(A) T2: Write(A)
This schedule is not conflict-serializable because swapping conflicting operations cannot
make it equivalent to any serial schedule.
View Serializability:A schedule is view-serializable if it is view-equivalent to a serial
schedule.
View-Equivalent:1]Initial reads of each data item in the schedule are the same.2]Final
writes of each data item in the schedule are the same.3]Intermediate operations produce
the same result.
Example: Consider:1]Schedule S1: T1: Read(A), Write(A) T2: Read(A),
Write(A)2]Serial Schedule:T1: Read(A), Write(A) T2: Read(A),
Write(A)If both schedules lead to the same database state, they are view-
equivalent and thus view-serializable.

Q4) a) Explain with example, recoverable and non recoverable schedules.


Recoverable Schedules:
A schedule is recoverable if a transaction commits only after all the transactions whose
changes it has read have committed. This ensures that in case of a failure, the database
can be recovered to a consistent state.Example of a Recoverable Schedule:
Consider two transactions T1T_1T1 and T2T_2T2:
1. T1:W(A)T_1: W(A)T1:W(A), T2:R(A)T_2: R(A)T2:R(A), T1:CommitT_1:
CommitT1:Commit, T2:CommitT_2: CommitT2:Commit
o T2T_2T2 reads AAA after T1T_1T1 writes AAA and commits after
T1T_1T1.
o If T1T_1T1 aborts, T2T_2T2 cannot commit, ensuring recoverability.
Non-Recoverable Schedules:
A schedule is non-recoverable if a transaction commits before a transaction whose
changes it has read commits. This can lead to an inconsistent state if the earlier
transaction aborts.
Example of a Non-Recoverable Schedule:T1:W(A)T_1: W(A)T1:W(A), T2:R(A)T_2:
R(A)T2:R(A), T2:CommitT_2: CommitT2:Commit, T1:AbortT_1: AbortT1:Abort
T2T_2T2 commits before T1T_1T1 commits. If T1T_1T1 aborts, the changes T2T_2T2
committed will be inconsistent.
b) What is need of concurrency control in database management? Explain

locking methods and deadlock handling. [6]


Need for Concurrency Control
Concurrency control is essential to:1]Maintain database consistency by ensuring ACID
properties.2]Prevent issues like dirty reads, uncommitted data, lost updates, and
unrepeatable reads during concurrent transaction execution.3]Enhance system
performance by allowing safe concurrent access.
Locking Methods
1. Binary Locks:A data item can either be locked or unlocked.Simple but lacks
flexibility for multiple transactions needing read access.
2. Shared and Exclusive Locks:1]Shared (S) Lock: Allows multiple transactions to
read a data item.2]Exclusive (X) Lock: Allows only one transaction to write to a
data item.Example: T1T_1T1 can acquire an S lock to read data, while T2T_2T2
cannot acquire an X lock until T1T_1T1 releases its S lock.
3. Two-Phase Locking (2PL):1]Growing Phase: Transactions acquire all required
locks.2]Shrinking Phase: Transactions release locks.3]Ensures conflict
serializability but may lead to deadlocks.
Deadlock Handling
1. Deadlock Prevention:Enforce protocols like wait-die (older transactions wait,
younger ones abort) or wound-wait (older transactions preempt younger ones).
2. Deadlock Detection and Resolution:Use a wait-for graph to detect cycles.Abort
one or more transactions to break the cycle.
3. Timeouts:Abort transactions that have been waiting for too long.

c) Explain need and role of Time-Stamp based protocols in database

management control. [5]


Need:
Time-stamp protocols ensure serializability by assigning a unique time-stamp to each
transaction. This eliminates the need for locks and reduces the chances of deadlocks.
Role in Concurrency Control:1]Time-Stamp Ordering Protocol:Transactions are
ordered based on their time-stamps.If a transaction TiT_iTi tries to access a data
item:1]Read Operation: Allowed if TiT_iTi’s time-stamp is greater than the last write
time-stamp of the item.2]Write Operation: Allowed if TiT_iTi’s time-stamp is greater
than both the last read and write time-stamps of the item.3]Otherwise, TiT_iTi is rolled
back.
2]Thomas’ Write Rule:A write operation is ignored if it has an older time-stamp than
the current write time-stamp of the data item. This optimizes unnecessary operations.
Advantages:Eliminates deadlocks.Ensures conflict serializability.Reduces waiting times
compared to locking mechanisms.
Example:Two transactions T1T_1T1 (time-stamp = 1) and T2T_2T2 (time-stamp = 2)
accessing the same item:1]T1T_1T1 writes first because it has an earlier time-
stamp.2]T2T_2T2 must wait or abort if it conflicts with T1T_1T1's operations.

MAY -24
Q3) a) Explain two phase locking protocol with example. [6]
The Two-Phase Locking Protocol (2PL) ensures conflict serializability by dividing the
execution of a transaction into two distinct phases:
1. Growing Phase:The transaction acquires all the locks it needs (shared or
exclusive).No lock is released during this phase.
2. Shrinking Phase:The transaction releases locks it no longer requires.No new
locks are acquired in this phase.
This protocol ensures that once a transaction releases a lock, it cannot request any more
locks, preventing cyclic dependencies.
Example:Consider two transactions T1T_1T1 and T2T_2T2:
• T1T_1T1: R(A),W(A),R(B),W(B)R(A), W(A), R(B), W(B)R(A),W(A),R(B),W(B)
• T2T_2T2: R(B),W(B),R(A),W(A)R(B), W(B), R(A), W(A)R(B),W(B),R(A),W(A)
Schedule following 2PL:
1. T1T_1T1: Acquires S lock on AAA → Reads AAA.
2. T1T_1T1: Upgrades to X lock on AAA → Writes AAA.
3. T2T_2T2: Waits for T1T_1T1 to release AAA.
4. T1T_1T1: Acquires S lock on BBB → Reads BBB.
5. T1T_1T1: Upgrades to X lock on BBB → Writes BBB.
6. T1T_1T1: Releases locks on AAA and BBB.
7. T2T_2T2: Acquires S lock on BBB → Reads BBB, and so on.
Conflict Serializability:
• The schedule is equivalent to executing T1T_1T1 followed by T2T_2T2, ensuring
serializability.
b) What are the ACID properties of the transaction? [6]
Atomicity:A transaction is an indivisible unit; all its operations are executed, or none
are.Example: In a fund transfer, either both debit and credit operations complete, or
neither does.
Consistency:Transactions transform the database from one consistent state to
another while preserving integrity constraints.Example: A bank database with a rule
that total account balance should remain constant before and after a transaction.
Isolation:Transactions execute independently without interference, ensuring
intermediate states are invisible to other transactions.Example: Two users transferring
money should not affect each other's operations.
Durability:Once a transaction commits, its changes are permanent, even in the event
of a system crash.Example: After a successful withdrawal, the new account balance
persists despite server failures.

c) Explain the concept of serial schedule and serializable schedule. [5]


Serial Schedule:A schedule where transactions execute one after the other, without
overlapping.Ensures no interleaving of operations from different transactions.Always
consistent and conflict-free.
Example: Transactions T1T_1T1 and T2T_2T2:
1. T1:R(A),W(A),R(B),W(B)T_1: R(A), W(A), R(B), W(B)T1
:R(A),W(A),R(B),W(B)
2. T2:R(A),W(A),R(B),W(B)T_2: R(A), W(A), R(B), W(B)T2
:R(A),W(A),R(B),W(B)
In a serial schedule:T1T_1T1 executes completely, followed by T2T_2T2, or vice versa.

Serializable Schedule:A non-serial schedule that produces the same results as a


serial schedule.Ensures database consistency while allowing concurrent execution.
Example: Transactions T1T_1T1 and T2T_2T2: 1]T1:R(A),W(A)T_1: R(A), W(A)T1
:R(A),W(A) 2]T2:R(A),W(A)T_2: R(A), W(A)T2:R(A),W(A)
Non-serial Schedule: 1]T1:R(A)T_1: R(A)T1:R(A) 2]T2:R(A)T_2: R(A)T2:R(A)
3]T1:W(A)T_1: W(A)T1:W(A) 4]T2:W(A)T_2: W(A)T2:W(A)
If the result of this schedule matches a serial execution (e.g., T1→T2T_1 \rightarrow
T_2T1→T2), it is serializable.
Difference:
A serial schedule has no interleaving of operations, whereas a serializable schedule
allows interleaving but preserves consistency equivalent to a serial schedule.
Q4) a) Explain when deadlock occurs and how to recover if dead lock takes
place. [6]
When Deadlock Occurs:
Deadlock occurs in a database system when two or more transactions are waiting for
each other to release resources, creating a cycle of dependency. No transaction can
proceed, resulting in a standstill.
Example:1]T1T_1T1 locks Resource A and waits for Resource B.2]T2T_2T2 locks
Resource B and waits for Resource A.3]Neither transaction can proceed, causing a
deadlock.
Recovering from Deadlock:
A]Deadlock Detection:Use a Wait-for Graph to detect cycles. Each transaction is a node,
and an edge is drawn if one transaction is waiting for another. A cycle indicates
deadlock.
B]Deadlock Resolution:
1]Abort Transactions: a]Terminate one or more transactions to break the
cycle.b]Choose transactions based on criteria like:Priority or age (e.g., abort younger
transactions first).Resource usage (e.g., abort transactions using fewer resources).
2]Rollback Transactions:Roll back transactions partially or entirely to free resources.
C]Deadlock Prevention:Use protocols like:1]Wait-Die: Older transactions wait, younger
ones abort.2]Wound-Wait: Older transactions preempt younger ones.
D]Deadlock Avoidance:Use resource allocation algorithms like Banker’s Algorithm to
avoid unsafe states.

b) Explain advantages of concurrent execution of transactions. [6]


1] Improved Resource Utilization:CPU and I/O devices remain busy, reducing idle
time.
2] Increased Throughput:More transactions are completed per unit of time.
3]Reduced Waiting Time:Transactions need not wait for others to complete entirely.
4] Enhanced Responsiveness:Short transactions can be completed quickly, improving
user experience.
5] Maximized Resource Sharing:Multiple transactions share resources efficiently
without conflicts.
6] Improved System Performance:Concurrency reduces bottlenecks and improves
overall performance.
7] Reduced Turnaround Time:Transactions are executed faster due to overlapping
operations.
8] Fault Tolerance:Concurrency mechanisms like recovery protocols ensure data
consistency even if failures occur.
10]Better Scalability:The system can handle more users or transactions simultaneously.
11] Minimized Latency:Concurrent execution minimizes delays by allowing parallel
processing.
12] Support for Multi-User Environments:Enables simultaneous access to the database
by multiple users.
13] Efficient Use of Transaction Pipelines:Overlapping read, write, and compute
operations optimize system pipelines.

c) Explain the concept of recoverable and non recoverable schedules with


suitable example. [5]
Recoverable Schedule:A schedule is recoverable if a transaction commits only after all
the transactions whose changes it has read have committed. This ensures the database
can be recovered to a consistent state.
Example:
Transactions T1T_1T1 and T2T_2T2:
1. T1:W(A)T_1: W(A)T1:W(A)
2. T2:R(A)T_2: R(A)T2:R(A)
3. T1:CommitT_1: CommitT1:Commit
4. T2:CommitT_2: CommitT2:Commit
Here, T2T_2T2 commits only after T1T_1T1 commits, ensuring recoverability.
Non-Recoverable Schedule:
A schedule is non-recoverable if a transaction commits before another transaction
whose changes it read commits. This can lead to an inconsistent state if the earlier
transaction aborts.
Example:
1. T1:W(A)T_1: W(A)T1:W(A)
2. T2:R(A)T_2: R(A)T2:R(A)
3. T2:CommitT_2: CommitT2:Commit
4. T1:AbortT_1: AbortT1:Abort
Here, T2T_2T2 commits before T1T_1T1 commits. If T1T_1T1 aborts, T2T_2T2's
committed changes will lead to inconsistency.
DEC_22

Q3) a) Explain commit and Roll back operations of transaction. [6]


Commit:
• A commit operation is used to make all changes made during a transaction
permanent in the database.
• It indicates a successful completion of the transaction and ensures data
consistency.
• Once a transaction is committed, the changes cannot be undone.
• Example: After transferring money from one account to another in a banking
system, a commit finalizes the update to both accounts.
Rollback:
• A rollback operation is used to undo all changes made during the transaction
and restore the database to its previous consistent state.
• It occurs when there is an error or failure, such as a power outage or constraint
violation, ensuring the integrity of the database.
• Example: If an error occurs during a money transfer, a rollback cancels the
transaction and ensures no partial updates are applied.

b) Explain how beadlock occurs? Which are the actions required for the
deadlock recovery process? [6]
How Deadlock Occurs:Deadlock occurs when two or more transactions are waiting
indefinitely for resources held by each other, creating a cycle of dependency.
• Example:
o Transaction T1 holds Resource R1 and waits for Resource R2.
o Transaction T2 holds Resource R2 and waits for Resource R1.
Actions for Deadlock Recovery:
1. Deadlock Detection:Use a wait-for graph to identify cycles among transactions.
2. Transaction Abortion:Abort one or more transactions involved in the deadlock
to break the cycle.Prefer aborting transactions with fewer updates or lower
priority.
3. Resource Preemption:Temporarily take resources from one transaction and
assign them to another to resolve the deadlock.
4. Timeout-Based Recovery:If a transaction waits beyond a certain threshold, it is
assumed to be in deadlock and is aborted.
c) Define the following terms. [5]
i) Concurrency ii) Timestamp iii) Timestamp ordering iv) Schedule v) Transaction
i) Concurrency:The simultaneous execution of multiple transactions to improve the
performance of a database system.Ensures correctness using protocols like locking or
timestamp ordering.
ii) Timestamp:A unique identifier assigned to each transaction or operation, typically
based on the time of its initiation.Used to maintain the sequence of operations and
ensure consistency.
iii) Timestamp Ordering:A concurrency control protocol that ensures transactions are
executed in the order of their timestamps.Older transactions are given higher priority to
prevent conflicts.
iv) Schedule:The sequence in which database operations (read/write) of transactions are
executed.Example: Serial schedules and non-serial schedules.
v) Transaction:A logical unit of work performed by a database, which must be either
fully completed (commit) or completely undone (rollback).Properties of transactions are
governed by ACID principles (Atomicity, Consistency, Isolation, Durability).

Q4) a) What are ACID properties of a transaction? [6]


b) Identify the following schedule is view serializable or not. Justify your
answer. [5]

Schedule Given:
T1: R(X), W(X), W(Z)
T2: W(Y)
T3: W(X)
Step 1: View Serializability Rules
A schedule is view serializable if it can be transformed into a serial schedule (executing
transactions one after another) while preserving the following:
1]Initial Read: The first read operation on a data item must match the serial
schedule.2]Write-After-Read: If a transaction reads a value written by another, the
same order must exist in the serial schedule.3]Final Write: The last write operation on
any data item must match the serial schedule.
Step 2: Analyze the Schedule 1]T1 reads and writes X, and writes Z. 2]T2 writes Y.
3]T3 writes X after T1. 4]The final write on X is by T3, and the final write on Y is by T2.
Justification:The order of operations on X ensures no conflicts with view serializability
because T1 writes first, and T3 writes last.The operations on Y (T2) are independent of
others.There are no violations of initial read, write-after-read, or final write rules.
Conclusion:The schedule is view serializable as it can be rearranged into a serial order:
T1 → T2 → T3 or T1 → T3 → T2.

c) Explain the transaction states with state diagram. [6]


Transaction States:
1. Active:The transaction begins execution and performs its operations.It remains
active unless an error occurs or it completes successfully.
2. Partially Committed:The transaction has completed its operations but has not
yet committed its changes.
3. Committed:The transaction successfully completes, and its changes are made
permanent in the database.
4. Failed:The transaction encounters an error during execution.
5. Aborted:The transaction is terminated, and all changes made are rolled back,
restoring the database to its previous state.

State Diagram:
Start

Active
↙ ↘
Aborted Partially Committed
↓ ↓
Failed Committed
• From Active, a transaction can either commit (move to Partially Committed) or
fail (move to Failed/Aborted).
• From Partially Committed, it moves to Committed if successful.
• From Aborted, it may restart or terminate entirely.
DEC - 23
Q3) State and explain the ACID Properties. During its execution, a transaction
passes through several states, untill it finally commits or aborts.
a) List all possible sequenices of states through which a transaction may
pass. Explain the situations when each state transaction occurs. [6]
ACID Properties of a Transaction
1. Atomicity:Ensures that a transaction is treated as a single unit. All operations
must either execute completely or not at all.Example: A bank transfer must debit
one account and credit another; if one operation fails, both are rolled back.
2. Consistency:Guarantees that the database transitions from one valid state to
another, maintaining all rules and constraints.Example: Transferring funds
between accounts must ensure the total funds remain constant.
3. Isolation:Ensures transactions do not interfere with each other. Intermediate
states of a transaction are invisible to other transactions.Example: While a
transaction updates an account, another transaction should not access it until the
update is committed.
4. Durability:Ensures that committed changes are permanent, even in case of a
system crash.Example: After a transaction commits, the updated data remains
saved.

Q3(a): Transaction States and Possible Sequences


During execution, a transaction transitions through several states:
1. Active:The transaction starts and performs operations like read/write.Situation:
A transaction is in progress and has not yet completed.
2. Partially Committed:The transaction completes its final operation but has not
yet committed.Situation: This state occurs just before the commit operation.
3. Committed:The transaction has successfully completed, and all changes are
made permanent.Situation: The database is updated, and the transaction ends
successfully.
4. Failed:An error occurs during execution, causing the transaction to
fail.Situation: This happens due to hardware issues, constraint violations, or
logical errors.
5. Aborted:The transaction is terminated, and all changes are rolled
back.Situation: This follows the failed state, ensuring the database remains
consistent.
Possible State Sequences:
1. Normal Execution:
o Active → Partially Committed → Committed
2. Failure During Execution:
o Active → Failed → Aborted
3. Failure During Commit:
o Active → Partially Committed → Failed → Aborted

b) Explain the concept of Serializability? Explain conflict serializability


with example. [6]
Serializability:
Definition:Serializability ensures that the execution of a concurrent schedule produces
the same result as a serial schedule (where transactions are executed one after
another).Serializability preserves the consistency of the database during concurrent
transactions.
Conflict Serializability:
Definition:A schedule is conflict serializable if it can be transformed into a serial
schedule by swapping non-conflicting operations.
Conflicting Operations:
Two operations conflict if:1]They belong to different transactions.2]They operate on the
same data item.3]At least one of them is a write operation.
Example of Conflict Serializability:
Schedule S: 1]T1: R(A) → W(A) 2]T2: R(A) → W(A)
Conflicts:1]T1's W(A) conflicts with T2's R(A).2]T2's W(A) conflicts with T1's W(A).
Conflict Graph:Create a directed graph where nodes represent transactions, and edges
represent conflicts:1]Edge from T1 to T2 (T1's W(A) → T2's R(A)).2]Edge from T2 to
T1 (T2's W(A) → T1's W(A)).
Cycle Detection:If there is a cycle in the conflict graph, the schedule is not conflict
serializable.If no cycle exists, the schedule is conflict serializable.
Conclusion:A conflict-free schedule ensures that the transactions can be serialized,
preserving consistency.
c) Consider the Transaction (T3), Transaction (T4) are any hypotheticaltransactions
working on data item Q. Schedule explaining the executionof T3, T4 are given below.
Decide whether following schedule is conflictserializable or not? Justify your answer:
[6] T3 T4 Read (Q) Write (Q) Write (Q)
Given Schedule:1]T3: Read(Q) → Write(Q) 2]T4: Write(Q)
Step 1: Identify Conflicting Operations
Conflicting operations occur if:1]They belong to different transactions.2]They access
the same data item (Q).3]At least one of them is a write operation.
From the schedule:1]T3: Write(Q) conflicts with T4: Write(Q) (write-write conflict).
2]T3: Read(Q) conflicts with T4: Write(Q) (read-write conflict).
Step 2: Create a Precedence Graph (Conflict Graph)
1. Nodes: Represent the transactions (T3 and T4).
2. Edges:1]From T3 to T4 because T3: Read(Q) occurs before T4: Write(Q).2]From
T3 to T4 because T3: Write(Q) occurs before T4: Write(Q).
Precedence Graph:Node: T3, T4. Edge: T3 → T4
Step 3: Check for Cycles:The graph has a single direction (T3 → T4) with no cycles.
Step 4: ConclusionSince there are no cycles in the conflict graph, the schedule is conflict
serializable.The schedule can be serialized as T3 → T4, meaning T3 completes all its
operations before T4 starts.
Justification:The absence of cycles in the conflict graph guarantees that the schedule is
conflict serializable. Thus, it ensures the consistency of the database while maintaining
the order T3 → T4.

Q4) a) What do you mean by isolation? Why it is important? Give an


example.[6]
What is Isolation? Isolation is one of the ACID properties of transactions in a database
system.It ensures that transactions are executed independently of one another. The
intermediate states of a transaction should not be visible to other concurrent
transactions until the transaction is committed.Isolation prevents data inconsistencies
caused by the interference of multiple transactions.
Why is Isolation Important?1]Consistency: Prevents one transaction from seeing
incomplete or uncommitted changes of another, ensuring the database remains
consistent.2]Prevents Anomalies: Avoids issues such as dirty reads, non-repeatable
reads, and phantom reads, which can occur in concurrent environments.
Example:Consider two transactions in a bank system:1]T1: Transfers $100 from
Account A to Account B.2]T2: Reads the balance of Account A and Account B.
Without isolation, T2 might read an intermediate state where:Account A = $900
(deducted $100).Account B = $500 (transfer not yet added).
With isolation, T2 will only see the balances as:Account A = $1000.Account B = $500.
After T1 commits, T2 will see the updated balances:Account A = $900. Account B =
$600.
b) Explain the concept of concurrent execution? [6]
What is Concurrent Execution? Concurrent execution allows multiple transactions to
run simultaneously in a database system.It improves system performance and resource
utilization by overlapping I/O and CPU operations.
Advantages of Concurrent Execution:1]Improved Throughput: Multiple transactions
are executed in parallel, increasing the number of operations completed in a given
time.2]Resource Utilization: Overlapping I/O and CPU operations ensure efficient use
of system resources.3]Reduced Waiting Time: Transactions do not have to wait for
others to complete entirely before starting.
Challenges of Concurrent Execution:May lead to anomalies like:1]Dirty Reads: A
transaction reads uncommitted changes of another transaction.2]Non-Repeatable
Reads: Data read twice by a transaction changes because of another
transaction.3]Phantom Reads: A transaction sees new rows inserted by another
transaction during execution.
Example:
1]T1: Updates the balance of Account A.2]T2: Reads the balance of Account A.
Without proper synchronization, T2 may read an incorrect or intermediate balance.

c) Explain commit and role back operation of transactions? [6]


Commit Operation:The commit operation makes all changes made by a transaction
permanent in the database.Once committed, the changes cannot be undone.Use Case:
Commit is performed when a transaction completes successfully.Syntax ::COMMIT;
Example:A bank transfer debits $100 from Account A and credits $100 to Account
B.After successful execution, the transaction is committed, ensuring the updates are
permanent.
Rollback Operation:The rollback operation undoes all changes made by a transaction
and restores the database to its previous consistent state.It is used when an error or
failure occurs during the transaction.Syntax :: ROLLBACK;
Example:If an error occurs while transferring $100 from Account A to Account B, a
rollback ensures the changes are canceled, leaving Account A and Account B unaffected.

Aspect Commit Rollback

Reverts changes to the previous


Action Makes changes permanent.
state.

After successful completion of a


When Used On encountering an error or failure.
transaction.

Effect on Changes are visible to all Changes are invisible, restoring


Data transactions. consistency.
MAY -22

Q.3 a]explain the basic concept of transaction and property of transaction


A transaction in a database is a sequence of operations performed as a single logical unit
of work. It represents a program's interaction with the database to retrieve, update, or
manage data.A transaction ensures the integrity of the database by following a well-
defined sequence of operations that must adhere to specific rules to maintain
consistency.
Properties of a Transaction (ACID Properties)
1. Atomicity::Definition: A transaction is an all-or-nothing operation.Example: In a
bank transfer, either both debit and credit operations are completed, or neither is
performed.
2. Consistency::Definition: Ensures that a transaction leaves the database in a consistent
state by adhering to all constraints and rules.Example: After a money transfer, the total
balance across accounts should remain the same.
3. Isolation::Definition: Ensures that the execution of one transaction does not affect
others. Each transaction appears to execute in isolation.Example: While one transaction
is updating a record, another transaction cannot read or modify that record until the
update is complete.
4. Durability::Definition: Once a transaction is committed, the changes it made are
permanent and stored safely, even in the event of a failure.Example: After successfully
saving a customer's order, the data remains intact even if the server crashes.
Example of a Transaction ::A transaction to transfer $500 from Account A to Account
B:1]Check the balance of Account A.2]Deduct $500 from Account A.3]Add $500 to
Account B.4]Commit the transaction.
If any step fails (e.g., insufficient balance in Account A), the transaction is rolled back,
leaving the database unchanged.
Importance of Transactions ::Maintain database consistency.Prevent data corruption
in case of failures.Enable concurrent user access without interference.Allow for reliable
error recovery through rollback mechanisms.

b) explain concept of schedule what is serial schedule


A schedule is an arrangement of operations (like Read, Write, Commit, or Abort) from
multiple transactions executed by a database system. The order of these operations
determines how the transactions interact with each other and with the database.
Types of Schedules
1. Serial Schedule:A schedule where transactions are executed one after another
without interleaving.In this schedule, one transaction completes entirely before
another begins.Ensures the same results as if the transactions were executed in
isolation.
2. Non-Serial Schedule:A schedule where operations of two or more transactions
are interleaved.It improves concurrency and system throughput.It may lead to
conflicts if not carefully managed.

Serial Schedule
Definition:
A schedule is serial if the operations of each transaction are executed sequentially, with
no interleaving of operations from other transactions. It preserves the integrity of
transactions because each transaction is executed independently of others.
Example of Serial Schedule:
Transactions:T1:
Read(A); A = A + 10; Write(A);T2:
Read(B); B = B * 2; Write(B);
Serial Schedule:1]Execute all operations of T1: T1: Read(A) → A = A + 10 → Write(A)
2]Then execute all operations of T2: T2: Read(B) → B = B * 2 → Write(B)
Properties of Serial Schedule:1]Consistency:Produces a consistent state of the database
since transactions do not interfere with one another.2]No Concurrency Issues:No
conflicts arise because transactions are executed sequentially.
Advantages of Serial Schedule:Simple to implement.Always maintains database
consistency.
Disadvantages of Serial Schedule:Low efficiency due to lack of concurrency.Slower
performance in multi-user environments.

c)expain with example deadlock handling in concurrency control


A deadlock occurs in a database system when two or more transactions are waiting for
each other to release resources, and none of them can proceed. This results in an
indefinite wait state. Deadlocks are common in concurrent transaction execution when
transactions lock resources and request additional resources held by others.
Example of Deadlock
Transactions:1]T1 locks Resource R1 and requests Resource R2 2]T2 locks Resource
R2 and requests Resource R1.
Deadlock State:1]T1 locks R1. 2]T2 locks R2. 3]T1 requests R2 but is blocked because
T2 holds R2. 4]T2 requests R1 but is blocked because T1 holds R1.
Both transactions are now in a deadlock state, waiting for each other to release the
locked resource.
Deadlock Handling Techniques
1. Deadlock Prevention
Ensure that a deadlock cannot occur by designing the system in such a way that at least
one of the necessary conditions for a deadlock is not possible.
A]Wait-Die Scheme:Transactions are assigned a timestamp.A younger transaction
requesting a resource held by an older transaction is aborted ("dies").An older
transaction waits for a resource held by a younger one.
B]Wound-Wait Scheme:An older transaction requesting a resource held by a younger
transaction preempts it ("wounds" it).A younger transaction waits for a resource held
by an older transaction.
2. Deadlock Avoidance:::Use algorithms like the Banker’s Algorithm to pre-check
whether granting a resource request will lead to a deadlock.Resources are allocated only
if it is guaranteed that the system will remain in a safe state.
3. Deadlock Detection and Recovery
A]Detection:Periodically check for cycles in the wait-for graph (a directed graph where
nodes are transactions, and edges indicate waiting for resources).A cycle in this graph
indicates a deadlock.
B]Recovery:Abort one or more transactions involved in the deadlock.Use a heuristic
(e.g., abort the transaction with the least progress or smallest cost to rollback).

Q4 a] Explain with example transaction management


Transaction management is the process of managing a sequence of database operations
that are executed as a single logical unit of work, called a transaction. A transaction
ensures that the database remains in a consistent state even in the presence of system
failures or concurrent operations.
Key Concepts in Transaction Management
1. ACID PropertiesAtomicity: All operations in a transaction are completed or none are
applied. Consistency: The database moves from one consistent state to another.
Isolation: Transactions do not interfere with each other. Durability: Changes made by
committed transactions are permanent.
Components of Transaction Management
1]Transaction Control Statements:BEGIN TRANSACTION / START TRANSACTION:
Marks the beginning of a transaction. COMMIT: Permanently saves the
changes made by the transaction.ROLLBACK: Reverts changes made by the
transaction to the state before it started.
2]Concurrency Control: Ensures that multiple transactions can execute simultaneously
without conflicts or inconsistencies
.3]Recovery Management: Ensures the database is restored to a consistent state in case
of failures.
Example of Transaction Management
Scenario: Bank Fund Transfer
Goal: Transfer $500 from Account A to Account B.
Steps in Transaction:1]Read the balance of Account A.2]Deduct $500 from Account
A.3]Add $500 to Account B.4]Commit the transaction.
Features of Transaction Management :::1]Atomicity: If any part of the transaction fails,
the entire transaction is rolled back, ensuring no partial updates.2]Concurrency:
Transaction management ensures consistent results even when multiple transactions
run concurrently.3]Error Recovery: Through mechanisms like rollback, the database
remains consistent in case of errors or system crashes.
Importance of Transaction Management :::1]Maintains Data Integrity: Prevents data
corruption during concurrent execution or system failures.2]Provides Isolation: Ensures
that intermediate states of a transaction are not visible to other transactions.3]Enhances
User Experience: Simplifies complex operations by treating them as a single unit of
work.

b) explain serializability wih respect to conflict and view


Serializability
Serializability is the primary criterion for the correctness of a schedule in a database. It
ensures that the results of executing a concurrent schedule are the same as those of a
serial schedule.
1. Conflict Serializability
• Definition: A schedule is conflict-serializable if it can be transformed into a serial
schedule by swapping non-conflicting operations without changing the outcome.
• Conflicting Operations: Two operations conflict if:
1. They belong to different transactions.
2. They access the same data item.
3. At least one of them is a WRITE operation.

2. View Serializability
• Definition: A schedule is view-serializable if it produces the same final result as a
serial schedule, even if operations cannot be swapped as in conflict serializability.
• Conditions for View Serializability:
1. Initial Reads: Each transaction reads the same initial value as in the serial
schedule.
2. Writes: The write operations result in the same final value for all data
items.
3. Read-After-Write Dependency: The transactions that read a value written
by another transaction must do so in the same order as in the serial
schedule.

c)what is need of locking method explain its type of in short


Need for Locking Method
Locks are essential in transaction management to maintain database consistency,
isolation, and integrity during concurrent transaction execution. They prevent problems
like lost updates, dirty reads, and uncommitted data being accessed by others.
Types of Locks
1. Binary Locks:A data item can either be locked (1) or unlocked (0).Simple to
implement but lacks flexibility.
2. Shared Lock (Read Lock):Multiple transactions can hold a shared lock on a data
item simultaneously, allowing only read operations.
3. Exclusive Lock (Write Lock):Only one transaction can hold an exclusive lock on
a data item, allowing read and write operations but blocking all others.
4. Two-Phase Locking (2PL):Growing Phase: Transactions acquire locks and do
not release any.Shrinking Phase: Transactions release locks and do not acquire
any new locks.Ensures conflict-serializable schedules.
5. Deadlock-Free Locking:Implements techniques like timeout or deadlock
detection to prevent or handle deadlocks effectively.
Importance of Locking::1]Maintains Isolation: Ensures that transactions do not
interfere with each other.2]Preserves Consistency: Prevents conflicts like dirty reads or
lost updates.3]Enables Serializability: Guarantees correct execution of concurrent
transactions.

You might also like