sql / intermediate
Snippet
Setting Read Committed Transaction Consistency Constraints
The SET TRANSACTION statement configures isolation properties for subsequent operations. Setting READ COMMITTED prevents dirty reads by ensuring queries only read data committed before the query execution began.
snippet.sql
sql
1
2
3
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;SELECT balance FROM accounts WHERE account_id = 42;COMMIT;
Breakdown
1
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
Configures the transaction to ignore uncommitted changes from concurrent transactions.
2
SELECT balance FROM accounts WHERE account_id = 42;
Reads data under the defined READ COMMITTED isolation guarantee.
3
COMMIT;
Ends the transaction block and releases acquired isolation scope locks.