Transactions & Concurrency Flashcards
Transactions: BEGIN, COMMIT, ROLLBACK Savepoints and nested transactions ACID properties: Atomicity, Consistency, Isolation, Durability Isolation levels: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE Locking: Shared vs Exclusive locks Deadlocks and prevention (35 cards)
What is a transaction in SQL?
A transaction is a sequence of operations performed as a single logical unit of work, using BEGIN, COMMIT, and ROLLBACK.
What does COMMIT do in SQL?
COMMIT makes all changes made during the transaction permanent in the database.
What does ROLLBACK do in SQL?
ROLLBACK undoes all changes made during the transaction, reverting the database to its previous state.
What are savepoints in SQL?
Savepoints allow partial rollbacks within a transaction by marking intermediate points.
What are nested transactions?
Nested transactions simulate sub-transactions using savepoints but aren’t fully supported in all DBMSs.
What does the ACID acronym stand for?
Atomicity, Consistency, Isolation, Durability — the key properties of a reliable transaction.
What is Atomicity in ACID?
Ensures all operations in a transaction succeed or none do, maintaining database integrity.
What is Consistency in ACID?
Ensures a transaction transforms the database from one valid state to another, enforcing rules.
What is Isolation in ACID?
Ensures concurrent transactions do not interfere with each other’s intermediate states.
What is Durability in ACID?
Ensures committed data is permanently stored and survives system failures.
What is READ UNCOMMITTED isolation?
Allows reading uncommitted changes, risking dirty reads.
What is READ COMMITTED isolation?
Prevents dirty reads but allows non-repeatable reads and phantom reads.
What is REPEATABLE READ isolation?
Prevents dirty and non-repeatable reads but may allow phantom reads.
What is SERIALIZABLE isolation?
The strictest level — fully isolates transactions as if executed serially, preventing all anomalies.
What is a shared lock?
Allows multiple transactions to read a resource but not modify it.
What is an exclusive lock?
Prevents any other transaction from reading or writing the locked resource.
What causes a deadlock in SQL?
A circular wait condition where two or more transactions are waiting for each other’s resources.
What is deadlock prevention?
Techniques like timeout, resource ordering, and wait-die schemes to avoid circular waits.
What’s the advantage of using transactions?
They ensure data consistency, integrity, and error recovery.
What’s a disadvantage of transactions?
They may increase complexity and cause contention or deadlocks in high-concurrency systems.
What is a best practice for transactions?
Keep transactions short, well-scoped, and avoid user interaction during them.
What is a common use case for savepoints?
Undoing specific parts of a transaction while preserving others.
How do transactions impact system design?
They help ensure consistency but require careful handling in distributed or high-concurrency systems.
What are architectural implications of isolation levels?
Higher isolation improves accuracy but reduces concurrency and performance.