Week 1 - Introduction to Advance DB Concepts
Week 1 - Introduction to Advance DB Concepts
ke
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
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,
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: [email protected]
• Ensure that both operations are executed together, so if one fails, the other is also
rolled back.
BEGIN TRANSACTION;
COMMIT;
If any of the updates fails (e.g., due to insufficient funds), the entire transaction is rolled
BEGIN TRANSACTION;
2);
COMMIT;
If any part of this transaction fails, the entire transaction is rolled back to maintain the
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
2. Properties of Transactions
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:
• 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.
an atomic transaction. If the transfer fails at any point, the entire operation is rolled
2. Consistency:
• Definition: Consistency ensures that a transaction brings the database from one
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.
• 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
• 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.
should be stored safely and not lost, even if the server crashes.
5. Serializability:
• Explanation: It prevents anomalies like lost updates and uncommitted data from
one account and depositing it into another is correctly ordered, even when multiple
Abdulrahman A. Mohamed Mobile: +254 713 500 814 Email: [email protected]
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
3. Models of Transactions:
SQL statements.
efficiently.
new customer record, updating their order, and committing the changes.
• The structured transaction model includes control structures like loops and
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
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.
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