0% found this document useful (0 votes)
4 views

Lecture_2 database

The document explains the concept of transactions in database management, highlighting their importance in maintaining database consistency through operations like COMMIT and ROLLBACK. It outlines the ACID properties of transactions—Atomicity, Consistency, Isolation, and Durability—and describes how a transaction log is used for recovery and management. Additionally, it details the basic operations of reading and writing data items in a database.

Uploaded by

goliemate
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)
4 views

Lecture_2 database

The document explains the concept of transactions in database management, highlighting their importance in maintaining database consistency through operations like COMMIT and ROLLBACK. It outlines the ACID properties of transactions—Atomicity, Consistency, Isolation, and Durability—and describes how a transaction log is used for recovery and management. Additionally, it details the basic operations of reading and writing data items in a database.

Uploaded by

goliemate
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/ 19

Transaction

Processing,
and Management

Ali El-Bastawissy 1
What is a
Transaction?

Ali El-Bastawissy 2
What is a Transaction?
 A database request is the equivalent of
a single SQL statement in an application
program or transaction.
 A transaction that changes the contents of
the database must alter the database from
one consistent database state to another.
 To ensure consistency of the
database, every transaction must
begin with the database in a known
consistent state.
Ali El-Bastawissy 3
Example of
Transaction
Amount in stock = X

X = 100 Initial State <Consistent State>

X = X - 50 Transaction <Modifies database>


A

X = 50 Final State <Consistent State>

Ali El-Bastawissy 4
Multi-Updates
Transaction
An accountant wishes to register the credit
sale of 100 units of product X to customer Y in
the amount of $500.00:
 Reducing product X’s Quantity on hand by 100.
 Adding $500.00 to customer Y’s accounts
receivable.
UPDATE PRODUCT SET PROD_QOH = PROD_QOH - 100
WHERE PROD_CODE = ‘X’;
UPDATE ACCREC SET AR_BALANCE = AR_BALANCE + 500
WHERE AR_NUM = ‘Y’;
If the above two transactions are not completely executed,
the transaction yields an inconsistent database.

Ali El-Bastawissy 5
Example of
Transaction
Amount in Items X & Y

X = 1000
Y = 7000 Initial State <Consistent State>

X = X – 100 Transaction <Modifies database>


Y = 7000 + 500

X = 900 Final State <Consistent State>


Y = 7500

But
HOWwwww?
Ali El-Bastawissy 6
Transaction Management with
SQL
 Transaction support is provided by 2 SQL
statements:
 COMMIT
 ROLLBACK
 When a transaction sequence is initiated, it must
continue through all succeeding SQL
statements until one of the following four events
occurs:
 A COMMIT statement is reached.
 A ROLLBACK statement is reached.
 The end of a program is successfully reached
(COMMIT
Like).
 The program is abnormally terminated (ROLLBACK
Ali El-Bastawissy 7
Transaction Management with
SQL
 Our last example:
UPDATE PRODUCT
SET PROD_QOH = PROD_QOH - 100
WHERE PROD_CODE = ‘X’;
UPDATE ACCREC
SET AR_BALANCE = AR_BALANCE +
500
WHERE AR_NUM = ‘Y’;
COMMIT;

Ali El-Bastawissy 8
A Transaction Processing
Example

Ali El-Bastawissy 9
Transaction ACID
 Atomic
Properties
 All operations of a transaction should be completed; if not,
the transaction is aborted.
 Transactions cannot be subdivided
 Consistent
 Transaction must alter the database from one consistent
state to another consistent state.
 Isolated
 Data used during the execution of a transaction cannot be
used by a second transaction until the first one is
completed.
 Durable
 Database changes are permanent
 The permanence of the database’s consistent state.

Ali El-Bastawissy 10
How DBMSs Manage Transactions??

Ali El-Bastawissy 11
The Transaction Log
 Transaction log stores:
A record for the beginning of transaction
For each transaction operation:
○ Type of operation being performed (update,
delete, insert)
○ Names of objects affected by transaction
○ “Before” and “after” values for updated fields
○ Pointers to previous and next transaction
log entries for the same transaction
Ending (COMMIT) of the transaction

Ali El-Bastawissy 12
 The information stored in the log is used by
the DBMS for a recovery requirement
triggered by a ROLLBACK statement or a
system failure.
 In such cases, the DBMS returns back the
before data image to get the initial consistent
state.
 The transaction log is itself a database, and it
is managed by the DBMS like any other
database.

Ali El-Bastawissy 13
Ali El-Bastawissy 14
Transaction Processing

 A database is a collection of named data items


 Data Item: a field, a record , or a whole disk block
 Basic operations:
read_item(X): Reads a database item named X into
a program variable. To simplify our notation, we assume
that the program variable is also named X.
write_item(X): Writes the value of program
variable
X into the database item named X.
Transaction Processing

READ AND WRITE OPERATIONS:

 read_item(X) command includes the following steps:


 Find the address of the disk block that contains item X.
 Copy that disk block into a buffer in main memory (if that disk
block is not already in some main memory buffer).
 Copy item X from the buffer to the program variable named
X.

 write_item(X) command includes the following steps:


 Find the address of the disk block that contains item X.
 Copy that disk block into a buffer in main memory (if that
disk block is not already in some main memory buffer).
 Copy item X from the program variable named X into its
correct location in the buffer.
 Store the updated block from the buffer back to disk
Introduction to Transaction
Processing (5)
READ AND WRITE OPERATIONS (cont.):
 write_item(X) command includes the following steps:
 Find the address of the disk block that contains item X.
 Copy that disk block into a buffer in main memory (if that
disk block is not already in some main memory buffer).
 Copy item X from the program variable named X into
its correct location in the buffer.
 Store the updated block from the buffer back to disk
(either
immediately or at some later point in time).
TRANSACTION STATES

Ali El-Bastawissy 18
Assignment

Please write everything about Concurrency


Control in RDB.

19

You might also like