A Non-Repeatable Read occurs when a transaction reads the same row twice and gets different values because another transaction modified and committed that row between the two reads. The row itself remains the same, but the data inside the row changes. Non-Repeatable Reads are possible under READ COMMITTED and READ UNCOMMITTED isolation levels. They are prevented by REPEATABLE READ, SNAPSHOT, and SERIALIZABLE isolation levels.
See the demo
Running this
query
|
BEGIN TRAN; SELECT * FROM Account WHERE AccountNumber='SB100001' |
Now we are
updating the same record in other session
|
update Account set Balance=60000.00 WHERE AccountNumber='SB100001' |
Record updated
successfully.
Now we are
running the session 1 read query
We have not do
any thing but our query has changed the result. This is called non-repeatable.
|
Feature |
Non-Repeatable
Read |
Phantom
Read |
|
Same
Row? |
Yes |
No |
|
Value Changes? |
Yes |
Not necessarily |
|
Row
Count Changes? |
No |
Yes |
|
Caused By |
UPDATE |
INSERT / DELETE |
|
Example |
Salary
changed |
New
employee appears |
No comments:
Post a Comment
If you have any doubt, please let me know.