click below
click below
Normal Size Small Size show me how
DATABASE - 4
Transaction and Concurrency Control
| Question | Answer |
|---|---|
| Is a group of one or more database operations that are treated as one single unit. | transaction |
| Either ALL operations succeed | COMMIT |
| Or ALL operations fail | ROLLBACK |
| save changes | COMMIT |
| undo everything | ROLLBACK |
| Is a file used by the DBMS to record all changes made to the database. | Transaction log |
| What is A.C.I.D? | Atomicity Consistency Isolation Durability |
| All operations succeed or fail together | Atomicity |
| Data remains correct and valid | Consistency |
| Transactions don’t interfere with each other | Isolation |
| Data is saved permanently after commit | Durability |
| ACID Properties | ACID Properties |
| A transaction must fully complete or not happen at all | Atomicity (All or Nothing) |
| he database must always follow rules and constraints. | Consistency (Always Valid Data) |
| Transactions should not affect each other while running. | Isolation (No Interference) |
| Once a transaction is committed, it is permanent | Durability (Permanent Save) |
| control how transactions interact with each other when running at the same time. | Isolation Levels & Concurrency |
| Isolation Levels Determine | What data a transaction can see • Whether changes from other transactions are visible |
| Common Problems in Concurrency: | Common Problems in Concurrency: |
| Reading data that another transaction has changed but not yet saved (committed). | Dirty Read |
| Reading the same row twice but getting different values because another transaction modified it in between. | Non-Repeatable Read |
| Re-running a query returns new or missing rows because another transaction inserted or deleted data. | Phantom Read |
| more accurate but slower | Higher isolation |
| faster but risky | Lower isolation |
| Isolation Levels: | Isolation Levels: |
| Lowest isolation level. Allows reading uncommitted (temporary) data, Can cause dirty reads. | READ UNCOMMITTED |
| Only reads committed data. Prevents dirty reads, allows nonrepeatable reads. | READ COMMITTED (Default) |
| Ensures same data is returned when re-read. Prevents: dirty reads & nonrepeatable reads, still allows phantom reads. | REPEATABLE READ |
| Highest isolation level (strictest). Prevents dirty reads, non-repeatable reads & phantom reads. | SERIALIZABLE |
| Two transactions are waiting for each other’s resources, and neither can continue. | Deadlock |
| Causes of Deadlocks: | • Transactions use same data at the same time • They access data in different order • Transactions takes too long • Too many locks on tables/rows |