Aan de slagGa gratis aan de slag

Prevent dirty reads

You have to analyze how many accounts have more than $50,000.

As the number of accounts is an important result, you don't want to read data modified by other transactions that haven't committed or rolled back yet. In doing this, you prevent dirty reads. However, you don't need to consider having non-repeatable or phantom reads.

Prepare the script.

Deze oefening maakt deel uit van de cursus

Transactions and Error Handling in SQL Server

Cursus bekijken

Oefeninstructies

  • Set the appropriate isolation level to prevent dirty reads.
  • Select the count of accounts that match the criteria.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- Set the appropriate isolation level
SET TRANSACTION ___ ___ ___ ___

-- Count the accounts
SELECT ___(*) AS number_of_accounts
FROM accounts
WHERE current_balance >= 50000;
Code bewerken en uitvoeren