1
A transaction is a unit of work that
consists of one or more actions for
accessing or changing the contents of a
database.
Tbl_Order
OrderID OrderDate Customer Total DiscountRate
Tbl_Order_Items
OrderID ProductID Quantity
Tbl_Products
ProductID ProductName Price Stock
4
Tbl_Customer
CustomerName Address INSERT
Tbl_Order
OrderID OrderDate Customer Total DiscountRate INSERT
Tbl_Order_Items
OrderID ProductID Quantity INSERT
Tbl_Products
ProductID ProductName Price Stock UPDATE
5
Tbl_Customer
CustomerName Address
Tbl_Order
OrderID OrderDate Customer Total DiscountRate DELETE
Tbl_Order_Items
OrderID ProductID Quantity DELETE
Tbl_Products
ProductID ProductName Price Stock UPDATE
6
7
8
Tbl_Flights
FlightNum Number_of_Seats Vacant_seats
AA123 250 150
Tbl_Reservations
FlightNum Agent Num_seats_reserved
AA123 Ahmad 6
AA123 Ali 14
AA123 Abu 8
AA123 Siti 12
9
“Make 40 new seat reservations”
Before
Number of Seats 250
Reservations 100
Vacant seats 150
10
“Make 40 new seat reservations”
Before Transaction
Number of Seats 250
Reservations 100 + 40
Vacant seats 150 - 40
11
“Make 40 new seat reservations”
12
Completion of a transaction results in
one of two possible outcomes
14
ACID (s) :-
1. Atomicity
2. Consistency Preservation
3. Isolation (Concurrency control)
4. Durability (Permanence)
Also
5. Serializablity
15
1. Atomicity
A transaction is a single unit of work or
basic process.
Each operation in the transaction must be
performed completely or not at all.
2. Consistency Preservation
A transaction that has been correctly
executed must change the database from
one consistent state to a different
consistent state.
16
3. Isolation (Concurrency control)
A transaction cannot allow the data that it
is currently updating to be accessed by
other transactions, before the original
transaction has been committed.
4. Durability (Permanence)
When a transaction changes a database the
change is successful (i.e. has been
committed), the change cannot be undone
or lost due to future failures.
17
New from your textbook:
5. Serializability
The schedule for concurrent execution of
multiple simultaneous transactions will
always yield consistent result. (For multi-
user and distributed databases only)
18
Definition
19
DB App
Client
DB App
Client
DBMS
DB
Application DB App
Client
Server
20
Answer:
◦ To prevent database failures resulting from system
errors or faults.
Example:
◦ We have a table called RESERVATIONS that stores
the names of customers on aeroplane flights. We
want to add a new customer to the RESERVATIONS
table. The transaction is performed as follows.
21
Number of 250
seats
Reservations 100
Vacancies 150
Before
Number of 250
seats
Reservations 100
Vacancies 150
22
DB App
Client
DB App
Client
DBMS
DB
Application DB App
Client
Server
23
Number of seats 250
Reservations 100 + 40
Vacancies 150
Before Transaction
(add
Reservation)
Number of seats 250
Reservations 100 + 40
Vacancies 150
24
Number of 250
seats
Reservations 100 + 40
Vacancies 150
Before Transaction
(add
Reservation)
Number of 250
seats
Reservations 100 + 40
Vacancies 150
25
DB App
Client
DB App
Client
DBMS
X
DB
Application DB App
Client
Server
26
Number of 250
seats
Reservations 100 + 40
Vacancies 150 - 40
Reservations 100 + 40 X
Vacancies 150 X
27
Number of 250 250
seats
28
ROLLBACK: SQL operation that reverts
uncommitted data back to their original
states
Assumes that SQL INSERT/UPDATE/DELETE
operations have not been COMMIT.
ROLLBACK will NOT work if all SQL operations
have been COMMIT.
The only way to UNDO is to run another
Transaction that reverses the previous
transactions
29
A database is in a consistent state when the
aggregated values stored in ALL table attributes in
one table, tallies (is equivalent) with the
aggregation of values stored all relevant rows in
other tables.
30
Answer:
1. It allows interleaving
2. It improves processing capacity (throughput)
31