Database Basics
Among the problems that occur when transactions run concurrently, which correctly describes a dirty read?
- AA transaction reads an update that another transaction has not yet committed, and because that transaction then rolls back, it ends up using a value that never existed
- BReading the same row twice within one transaction gives a different value, because another transaction updated the row and committed in between
- CRunning a search with the same condition twice gives a different number of rows, because another transaction added a row and committed in between
Show answer and explanation
Answer: A. A transaction reads an update that another transaction has not yet committed, and because that transaction then rolls back, it ends up using a value that never existed
A dirty read is the problem of reading uncommitted (not yet permanent) data. If the transaction that made the update later rolls back, the value read is one that was never made permanent, and any processing based on it is wrong. Finding that the same row has a different value when read twice is a non-repeatable read, and finding that rows matching a search condition have increased or decreased is a phantom read. These problems occur when transaction isolation is insufficient, and in SQL you choose how many of them to prevent by setting the isolation level. At isolation levels of READ COMMITTED and above, dirty reads do not occur.
- A. Correct. Reading an update that has not been committed is a dirty read.
- B. This describes a non-repeatable read.
- C. This describes a phantom read.