Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.
ke
TECHNICAL UNIVERSITY OF MOMBASA
CCI 4301: ADVANCED DATABASE MANAGEMENT SYSTEMS
WEEK 1: INTRODUCTION TO ADVANCED DATABASE CONCEPTS
OUTLINE
• 1. Introduction to Transactions
• 2. Properties of Transactions
• 3. Models of Transactions
1. Introduction to Transactions
Definition: A transaction in a database is a logical unit of work that consists of one or more
database operations. These operations can include data retrieval (read), data modification
(write), or a combination of both. Transactions are essential for maintaining the integrity
and consistency of a database.
Explanation: Transactions are used to ensure that a series of database operations are
executed as a single, indivisible unit. The ACID properties, which stand for Atomicity,
Consistency, Isolation, and Durability, govern the behavior of transactions
Examples: Let's consider some examples to illustrate the concept of a transaction:
Example 1: Money Transfer Suppose you are developing a banking application. To transfer
money from one account to another, you need a transaction to ensure the following:
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.ke
• Deduct the specified amount from Account A.
• Add the same amount to Account B.
• Ensure that both operations are executed together, so if one fails, the other is also
rolled back.
BEGIN TRANSACTION;
UPDATE AccountA SET Balance = Balance - 100 WHERE AccountNumber = '123';
UPDATE AccountB SET Balance = Balance + 100 WHERE AccountNumber = '456';
COMMIT;
If any of the updates fails (e.g., due to insufficient funds), the entire transaction is rolled
back, maintaining data consistency.
Example 2: Online Shopping In an online shopping application, when a customer places
an order, a transaction ensures the following:
• Deduct the purchased items' quantities from the inventory.
• Record the order details in the order history.
• Ensure that both actions are completed together.
BEGIN TRANSACTION;
UPDATE Inventory SET Quantity = Quantity - 2 WHERE ProductID = '789';
INSERT INTO OrderHistory (CustomerID, ProductID, Quantity) VALUES ('12345', '789',
2);
COMMIT;
If any part of this transaction fails, the entire transaction is rolled back to maintain the
integrity of the inventory and order history.
Transactions are a fundamental concept in database management, ensuring that database
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.ke
operations are reliable and consistent, even in the presence of errors or system failures.
They play a crucial role in various applications, from banking systems to e-commerce
platforms, where data integrity is paramount.
2. Properties of Transactions
Definition: Transactions in a database management system (DBMS) exhibit specific
properties, often referred to as ACID properties, which ensure the reliability and integrity
of database operations. ACID stands for Atomicity, Consistency, Isolation, and Durability.
1. Atomicity:
• Definition: Atomicity ensures that a transaction is treated as a single, indivisible unit
of work. It either executes in its entirety or not at all.
• Explanation: If any part of a transaction fails (e.g., due to an error or system crash),
the entire transaction is rolled back to its initial state, ensuring data consistency.
• Example: In a banking system, transferring money from one account to another is
an atomic transaction. If the transfer fails at any point, the entire operation is rolled
back, and the money remains in the source account.
2. Consistency:
• Definition: Consistency ensures that a transaction brings the database from one
consistent state to another, preserving data integrity and defined constraints.
• Explanation: The database must satisfy integrity constraints, such as referential
integrity or domain constraints, before and after a transaction.
• Example: In an e-commerce system, if a product is out of stock, the system must
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.ke
ensure that no orders can be placed for that product.
3. Isolation:
• Definition: Isolation ensures that concurrent transactions do not interfere with each
other. Each transaction appears to execute in isolation, even though they may run
concurrently.
• Explanation: Isolation levels, such as Read Uncommitted, Read Committed, and
Serializable, define the degree of isolation between transactions.
• Example: In a reservation system, two users booking seats on the same flight should
not see each other's reservations until both transactions are complete.
4. Durability:
• Definition: Durability guarantees that once a transaction is committed, its effects are
permanent and survive system failures.
• Explanation: Committed changes are stored in non-volatile storage (e.g., hard disk)
and are not lost, even in the event of a power outage or system crash.
• Example: In an email system, once an email is sent and acknowledged as sent, it
should be stored safely and not lost, even if the server crashes.
5. Serializability:
• Definition: Serializability is a higher-level property that ensures that a set of
concurrent transactions is equivalent to some serial execution of those transactions.
• Explanation: It prevents anomalies like lost updates and uncommitted data from
occurring in concurrent execution.
• Example: In a banking system, serializability ensures that transferring money from
one account and depositing it into another is correctly ordered, even when multiple
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.ke
users perform these transactions simultaneously.
In summary, the properties of transactions, including Atomicity, Consistency, Isolation,
Durability, and Serializability (ACID), are essential for maintaining data integrity and
ensuring reliable operations in database systems. These properties help prevent data
corruption and maintain database reliability, even in the presence of system failures and
concurrent access by multiple users.
3. Models of Transactions:
1. Flat Transaction Model:
• In a flat transaction model, a transaction is a simple sequence of one or more
SQL statements.
• It lacks any control structures or branching within the transaction.
• Transactions are straightforward but may not handle complex scenarios
efficiently.
Example: A transaction that consists of a sequence of SQL statements, such as inserting a
new customer record, updating their order, and committing the changes.
2. Structured Transaction Model:
• The structured transaction model includes control structures like loops and
conditional statements within a transaction.
• It allows for more complex transaction logic and error handling.
Example: A transaction that processes a batch of orders, checking each one for validity and
updating the inventory accordingly. If an order fails validation, the transaction can roll
back only that specific order's changes.
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: abdulrehman@tum.ac.ke
3. Nested Transaction Model:
• In the nested transaction model, a transaction can be divided into
subtransactions, each with its own ACID properties.
• Subtransactions can be committed or rolled back independently.
Example: A banking system that allows customers to perform multiple transactions within
a single session. Each transaction within the session can be committed or rolled back
separately.
4. Long-Running Transaction Model:
• Long-running transactions span extended periods and are typically used in
applications like online reservations or stock trading.
• They require mechanisms to handle partial failures and checkpointing to
ensure progress.
Example: An airline reservation system where a customer's seat selection and payment may
take place over a period of several minutes. The system must handle interruptions
gracefully.
Understanding these transaction models and their properties is crucial for designing
database systems that meet the requirements of various applications while ensuring data
integrity and consistency.