Challenge: Specifying Isolation Level for Transaction
Opgave
Swipe to start coding
We will now create a simple transaction using the BankAccounts
table and specify the isolation level for it.
This transaction will involve increasing the balance of one of the accounts and logging information about it in the log table.
Your task is to set the isolation level to SERIALIZABLE
for this transaction.
Løsning
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
BEGIN;
-- Start a transaction with SERIALIZABLE isolation level
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
-- Show the isolation level after setting it to SERIALIZABLE
SHOW TRANSACTION ISOLATION LEVEL;
-- Update the balance of the account
UPDATE BankAccounts
SET balance = balance + 100
WHERE account_number = 789;
-- Insert a log entry for the update
INSERT INTO UserLogs (account_number, action)
VALUES (789, 'Adding $100');
COMMIT;
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 8
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
BEGIN;
-- Start a transaction with SERIALIZABLE isolation level
___;
-- Show the isolation level after setting it to SERIALIZABLE
SHOW TRANSACTION ISOLATION LEVEL;
-- Update the balance of the account
UPDATE BankAccounts
SET balance = balance + 100
WHERE account_number = 789;
-- Insert a log entry for the update
INSERT INTO UserLogs (account_number, action)
VALUES (789, 'Adding $100');
COMMIT;
No query executed yet... |
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat