Challenge: Specifying Isolation Level for Transaction
Tarea
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.
Solución
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;
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 1. Capítulo 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... |
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla