Database Reference
In-Depth Information
Application Program
…………………………………
…………………………………
BEGIN
READ (savings);
savings : = savings - 50000
WRITE (savings);
READ (checking);
checking : = checking + 50000
WRITE (checking);
COMMIT
…………………………………
…………………………………
DATABASE
Savings
Account
$440,000
- 50,000
$390,000
Checking
Account
$10,000
+ 50,000
$60,000
Figure 15-1
Example of a successful transaction.
Application Program
…………………………………
…………………………………
BEGIN
READ (savings);
savings : = savings - 50000
WRITE (savings);
READ (checking);
checking : = checkin g + 5 000 0
ABORT
ROLLBACK
…………………………………
…………………………………
DATABASE
Savings
Account
$440,000
- 50,000
$390,000
Checking
Account
$10,000
+ 50,000
$440,000
Figure 15-2
Example of an aborted transaction.
transaction, the combined total amount in both accounts is $450,000; after the com-
pletion of the transaction, the combined total amount is still the same, preserving
data consistency.
Now assume that some program malfunction occurs immediately after the update
to the savings record but before the update to the checking record. The program
detects the malfunction and rolls back the effect of the update to the savings record.
Figure 15-2 shows the action of the transaction in this case. Note the BEGIN and
ROLLBACK statements demarking the start and end of the transaction.
In the successful execution of the transaction in the first case, the database is
taken from an old consistent state to a new consistent state. When program aborts
Search WWH ::




Custom Search