snippetsqlMinor
An uncommitted transaction updates a column; how can a different transaction see the old column value?
Viewed 0 times
canthecolumnuncommittedseevaluedifferenttransactionhowold
Problem
Let's assume the following case.
There is a
id | name
-----------------
1 | Mateus
A "User A" executes the following statement without committing the transaction:
Then a "User B" executes the following query:
User B will get the name
Is there a way to get the old name,
There is a
students table:id | name
-----------------
1 | Mateus
A "User A" executes the following statement without committing the transaction:
update students set name = 'Gustavo' where id = 1Then a "User B" executes the following query:
select * from students with (nolock) where id = 1User B will get the name
Gustavo, that's the expected behavior. The DB will return the uncommitted value because of the with(nolock) instruction.Is there a way to get the old name,
Mateus (the previously committed value), even when there's an uncommitted transaction?Solution
You can use Read Committed Snapshot Isolation (RCSI) on your database, which uses space in TempDB to keep track of committed versions of the data.
Be aware that RCSI adds 14 bytes to every versioned row, so you might see some additional page splits in the database. It also requires that TempDB's space and I/O be monitored to make sure it's not slowing things down.
Read more by Paul White and in this question.
Be aware that RCSI adds 14 bytes to every versioned row, so you might see some additional page splits in the database. It also requires that TempDB's space and I/O be monitored to make sure it's not slowing things down.
Read more by Paul White and in this question.
Context
StackExchange Database Administrators Q#238159, answer score: 4
Revisions (0)
No revisions yet.