My test table:
CREATE TABLE [dbo].[Personel](
[PersonelID] [int] NOT NULL,
[Name] [nchar](10) NULL,
CONSTRAINT [PK_Personel] PRIMARY KEY CLUSTERED
(
[PersonelID] ASC
)
)
My Test Data:
insert into Personel
values (1, 'Jack')
, (2, 'John')
, (3, 'Kevin')
Connection A:
begin tran
update Personel
set Name = 'Michael'
where PersonelID = 1
Connection B:
SET TRANSACTION ISOLATION LEVEL ????
SELECT Name
FROM Personel WITH (????)
where PersonelID = 1
Connection A starts a transaction and is trying to update data, but transaction is still going on. Connection B tries to read the data that is being updated.
Is there a way (an Isolation Level or a hint or combination of these two) to see the original data (Jack, not Michael) before the transaction is committed or rolled back?
You can access the old version of the data in the SNAPSHOT isolation level.
This requires that the database has snapshot isolation enabled before you start:
Then in connection B
There are some performance considerations with snapshot isolation, because it duplicates the rows read into tempdb.
Documentation reference