DBMS Interview Questions · Question 16

A transaction reads the same row twice but gets different values. Which anomaly has occurred?

Interview preparation resource from Gate Smashers.

Interview-ready answer

Non-repeatable read — a transaction reads the same row twice and gets different committed values because another transaction updated and committed that row between the two reads.

Understand it clearly

Direct answer

This is a non-repeatable read. It occurs when a transaction reads the same row twice and gets different committed values because another transaction updated that row and committed between the two reads.

Example

T1 reads an employee salary as 50,000. T2 updates that same salary to 60,000 and commits. When T1 reads the row again, it now sees 60,000. The same query against the same row has produced two different values during one transaction.

  • Scenario: T1 reads 50,000 → T2 updates to 60,000 and commits → T1 reads 60,000

How this differs from other anomalies

This is different from a dirty read because the second value is committed. It is also different from a phantom read, which normally concerns rows being added or removed from a result set that matches a condition.

Mitigation / isolation

Repeatable Read or a stronger isolation level is generally used when the same row must remain stable for repeated reads within a transaction, although exact behavior depends on the DBMS implementation.