Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Transaction:
A transaction is a sequence of operations that acts as a single, complete unit of
work. In simple terms, it's like a package of actions that need to happen together in a database. Imagine you're transferring money from your savings account to your checking account: 1. The transaction first deducts money from your savings account. 2. Then it adds that money to your checking account. Transactions ensure that either all steps happen together successfully, or none happen at all. ----------------------------------------------------------------------------------------------------------------- -------
Atomicity Example: Imagine transferring $100 from Alice's bank account to Bob's. In this transaction: o First, $100 is deducted from Alice's account.
o Then, $100 is added to Bob's account.
Atomicity ensures that either both steps happen, or neither does. If
there's an error after deducting $100 from Alice’s account but before adding it to Bob’s, the transaction will be rolled back, and Alice's balance will remain unchanged. This prevents partial updates. 2. Consistency Imagine an online shopping platform where a user’s order reduces the quantity of items in the store’s inventory. Let’s say there’s a rule that the total quantity of an item in the inventory cannot go below zero (because you can’t sell more than you have in stock). A user places an order to buy 5 units of a product, but the store only has 3 in stock. Consistency ensures that if this transaction is attempted, the system will reject it (or roll it back) because it would violate the rule. The transaction would either adjust the order quantity to match the available stock or deny the order, keeping the inventory in a consistent state. 3. Isolation Example: Two users, Jack and Jim, are both trying to buy the last item of a product at the same time: o Isolation ensures that each transaction operates as if it’s the only one occurring. So, if Jack completes his purchase first, Jill’s transaction won’t see the item as available. Jill will only proceed if the item is still in stock when her transaction is isolated and checked. 4. Durability Example: After a bank transaction is completed where $200 is deposited into Sarah’s account: o Durability guarantees that, once the transaction is committed, Sarah’s account will reflect the new balance permanently. Even if a power failure or crash occurs immediately after, the updated balance will remain intact and recoverable when the system is restored. Each ACID property helps maintain data reliability and integrity in transaction management.