Anda di halaman 1dari 31

TU2983 : Advanced Databases

1
 A transaction is a unit of work that
consists of one or more actions for
accessing or changing the contents of a
database.

 An application program can be


considered a series of transactions

 A transaction should change a database


from one consistent state to a different
consistent state.
2
3
Tbl_Customer
CustomerName Address

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”

Before Transaction After


Number of Seats 250 250
Reservations 100 + 40 140
Vacant seats 150 - 40 110

12
 Completion of a transaction results in
one of two possible outcomes

1. Success– known as a commit transaction


◦ The database achieves a new consistent
state.

2. Failure – known as an abort transaction


◦ The database must be restored to the
consistent state it was in before the
transaction began.
13
 Failed transactions must be rolled back to
bring the database back to the state it was in
before the beginning of the transaction.

 Transactions that have been committed


cannot be allowed to be rolled back.

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

◦ The prosess of managing multiple different


operations at the same time, with no interference
between operations.

 Concurrency control is needed to fulfil an


important database requirement:

◦ Permit many users to access and share the same


source of data.

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

Before Transaction Transaction


(add (deduct
Reservation) Vacancy)
Number of 250 X
seats

Reservations 100 + 40 X

Vacancies 150 X

27
Number of 250 250
seats

Reservations 100 + 40 140

Vacancies 150 - 40 110

Before Transaction Transaction After


(add (deduct
Reservation) Vacancy)
Number of 250 X 250 (X)
seats

Reservations 100 + 40 X 140

Vacancies 150 X 150 (X)

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.

 PROBLEM SOURCE: A user may not be the only


person updating the table.

 A database is not in a consistent state if only some


of the tables are consistent while others are not.

30
 Answer:
1. It allows interleaving
2. It improves processing capacity (throughput)

 A computer system is able to perform


multiple Input/Output (IO) operations in
parallel
 Processing time is saved/reduced if a
single operation can simultaneously
execute both an input (Write) and output
(Read) at the same time.

31

Anda mungkin juga menyukai