Get startedGet started for free

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.

This exercise is part of the course

Transactions and Error Handling in SQL Server

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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
___ ___
Edit and Run Code