SQL Server에서의 트랜잭션과 오류 처리
Miriam Antona
Software Engineer
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
| 더티 리드 | 비반복 읽기 | 팬텀 리드 | |
|---|---|---|---|
| READ UNCOMMITTED | yes | yes | yes |
| READ COMMITTED | no | yes | yes |
계정 5의 기존 잔액 = $35,000
Transaction1
BEGIN TRAN
UPDATE accounts
SET current_balance = 30000
WHERE account_id = 5;
Transaction2
...
...
...
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT current_balance
FROM accounts WHERE account_id = 5;
대기해야 함!
계정 5의 기존 잔액 = $35,000
Transaction1
BEGIN TRAN
UPDATE accounts
SET current_balance = 30000
WHERE account_id = 5;

COMMIT TRAN;
Transaction2
...
...
...
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT current_balance
FROM accounts WHERE account_id = 5;
| current_balance |
|-----------------|
| 30000,00 |
Transaction1
BEGIN TRAN
SELECT current_balance
FROM accounts WHERE account_id = 5;
Transaction2
...
...
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT current_balance
FROM accounts WHERE account_id = 5;
| current_balance |
|-----------------|
| 35000,00 |
장점:
단점:
사용 시점:
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
| 더티 리드 | 비반복 읽기 | 팬텀 리드 | |
|---|---|---|---|
| READ UNCOMMITTED | yes | yes | yes |
| READ COMMITTED | no | yes | yes |
| REPEATABLE READ | no | no | yes |
Transaction1
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRAN
SELECT current_balance FROM accounts
WHERE account_id = 5;
| current_balance |
|-----------------|
| 35000,00 |
Transaction2
...
...
UPDATE accounts
SET current_balance = 30000
WHERE account_id = 5;
대기해야 함!
Transaction1
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRAN
SELECT current_balance FROM accounts
WHERE account_id = 5;
SELECT current_balance FROM accounts
WHERE account_id = 5;
| current_balance |
|-----------------|
| 35000,00 |
COMMIT TRAN
Transaction2
...
...
UPDATE accounts
SET current_balance = 30000
WHERE account_id = 5;
대기해야 함!
Transaction1
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRAN
SELECT current_balance FROM accounts
WHERE account_id = 5;
SELECT current_balance FROM accounts
WHERE account_id = 5;
COMMIT TRAN
Transaction2
...
...
UPDATE accounts
SET current_balance = 30000
WHERE account_id = 5;
(1 rows affected)
장점:
단점:
REPEATABLE READ 트랜잭션에 의해 블로킹될 수 있음사용 시점:
SQL Server에서의 트랜잭션과 오류 처리