Complete the code to select all rows from the orders table.
SELECT * FROM [1];The orders table contains the data we want to read, so we select from it.
Complete the code to start a transaction with the isolation level that prevents dirty reads.
SET TRANSACTION ISOLATION LEVEL [1];The READ COMMITTED isolation level prevents dirty reads by only reading committed data.
Fix the error in the transaction code to prevent phantom reads.
BEGIN TRANSACTION;
SET TRANSACTION ISOLATION LEVEL [1];
-- perform queries
COMMIT;The REPEATABLE READ isolation level prevents phantom reads by ensuring consistent reads within a transaction.
Fill both blanks to write a query that counts orders with amount greater than 100 inside a repeatable read transaction.
BEGIN TRANSACTION; SET TRANSACTION ISOLATION LEVEL [1]; SELECT COUNT(*) FROM orders WHERE amount [2] 100; COMMIT;
We use REPEATABLE READ to prevent phantom reads and > to select orders with amount greater than 100.
Fill all three blanks to write a transaction that prevents dirty reads and phantom reads, and selects orders with status 'pending'.
BEGIN TRANSACTION; SET TRANSACTION ISOLATION LEVEL [1]; SELECT * FROM orders WHERE status = '[2]' AND amount [3] 0; COMMIT;
SERIALIZABLE is the strictest isolation level preventing dirty and phantom reads. We filter orders with status 'pending' and amount greater than 0.