Junior — Middle
Can you explain the concept of transaction isolation levels in SQL, especially what Repeatable Read is?
sobes.tech AI
Answer from AI
Transaction isolation levels in SQL determine how and when the changes made by one transaction become visible to other transactions. They help manage concurrency issues such as dirty reads, non-repeatable reads, and phantom reads.
Repeatable Read is an isolation level where a transaction guarantees that if it has read data, subsequent reads of the same data within the same transaction will not see changes. This prevents non-repeatable reads.
In practice, this means:
- The transaction sees the same data on repeated reads.
- Other transactions cannot modify or delete rows read by the current transaction until it completes.
- However, phantom reads (the appearance of new rows matching the query condition) can occur if the DBMS does not protect against them additionally.
Example: if within a transaction you perform the same SELECT query twice with the same condition, the result will be the same under Repeatable Read, even if another transaction tries to modify this data.