Junior — Middle
What transaction isolation levels are you aware of in SQL?
sobes.tech AI
Answer from AI
The main transaction isolation levels in SQL:
- Read Uncommitted — the lowest level. A transaction can read data that has not yet been committed (dirty read).
- Read Committed — the transaction sees only committed data. Dirty reads are prevented, but non-repeatable reads are possible.
- Repeatable Read — guarantees that data read in a transaction will not change until the transaction ends. It prevents non-repeatable reads but allows phantom reads (new rows matching the condition may appear).
- Serializable — the strictest level. Transactions are executed as if they were sequential, fully preventing phantom reads.
Example in PostgreSQL:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
-- operations
COMMIT;