CommencerCommencer gratuitement

Preventing non-repeatable reads

You are in charge of analyzing data about your bank customers.

You prepare a script that first selects the data of every customer. After that, your script needs to process some mathematical operations based on the result. (We won't focus on these operations for this exercise.) After that, you want to select the same data again, ensuring nothing has changed.

As this is critical, you think it is better if nobody can change anything in the customers table until you finish your analysis. In doing this, you prevent non-repeatable reads.

Cet exercice fait partie du cours

Transactions and Error Handling in SQL Server

Afficher le cours

Instructions

  • Set the appropriate isolation level to prevent non-repeatable reads.
  • Begin a transaction.
  • Commit the transaction.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

-- Set the appropriate isolation level
___ ___ ___ ___ ___ ___

-- Begin a transaction
___ ___

SELECT * FROM customers;

-- some mathematical operations, don't care about them...

SELECT * FROM customers;

-- Commit the transaction
___ ___
Modifier et exécuter le code