I've been playing around with the scripts bellow trying to better understand the snapshot isolation internals, but the behaviour is some times unexpected. I was expecting that every time I would run the select script bellow, something would show up on the dm_tran_version_store. But sometimes it comes up with no rows. I couldn't yet get a reason for that, and I have played with restarting the instance, changing the initial size of the data, changing the size of the updated data, etc.
The query I'm using to look at the version store is the one bellow, and some times it shows some rows, but some other times it comes empy
SELECT * FROM sys.dm_tran_version_store WHERE database_id=db_id('RowVerTest')
can anyone point me to something that I must be missing...?
regards,
/////////////////// CREATE DATABASE SCRIPT
USE [master]
SET NOCOUNT ON
SELECT GETDATE()
IF db_id('RowVerTest') IS NOT NULL
BEGIN
ALTER DATABASE [RowVerTest] set offline WITH ROLLBACK IMMEDIATE
ALTER DATABASE [RowVerTest] set online
DROP DATABASE [RowVerTest]
END
GO
CREATE DATABASE [RowVerTest]
ON PRIMARY
( NAME = N'RowVerTest', FILENAME = N'D:\DADOS\RowVerTest.mdf')
LOG ON
( NAME = N'RowVerTest_log', FILENAME = N'E:\LOGS\RowVerTest_log.ldf')
GO
--ALTER DATABASE [RowVerTest] SET ALLOW_SNAPSHOT_ISOLATION ON
--GO
USE [RowVerTest]
GO
CREATE TABLE test
(
c1 INT PRIMARY KEY,
c2 VARCHAR(8000)
)
GO
DECLARE @i INT
SET @i=1
WHILE @i<=8
BEGIN
INSERT INTO test VALUES (@i,REPLICATE(@i,900))
--INSERT INTO test VALUES (@i,REPLICATE(@i,10))
SET @i=@i+1
END
GO
ALTER DATABASE [RowVerTest] SET ALLOW_SNAPSHOT_ISOLATION ON
GO
SELECT GETDATE()
GO
/////////////////// SELECT SCRIPT
USE [RowVerTest]
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
SET NOCOUNT ON
SELECT GETDATE()
GO
BEGIN TRAN
--UPDATE test SET c2='XXXX'
--UPDATE test SET c2='XXXX' WHERE c1=1
UPDATE test SET c2=GETDATE() WHERE c1=1
WAITFOR DELAY '00:02:00'
COMMIT
SELECT GETDATE()
GO