I am doing the testing below to grasp the behavior of Snapshot Isolation level and Read Committed Snapshot.
Change Snapshot Isolation level ON & Read Committed Snapshot OFF
ALTER DATABASE AdventureWorks2019
SET ALLOW_SNAPSHOT_ISOLATION ON
ALTER DATABASE AdventureWorks2019 SET READ_COMMITTED_SNAPSHOT OFF
Transaction 1:
BEGIN TRANSACTION
UPDATE tblInventory
SET ItemsInStock = 5 WHERE Id = 1
COMMIT TRANSACTION
BEGIN TRANSACTION
SELECT ItemsInStock FROM tblInventory WHERE Id = 1
COMMIT TRANSACTION
Transaction 2:
BEGIN TRANSACTION
SELECT ItemsInStock FROM tblInventory WHERE Id = 1
COMMIT TRANSACTION
BEGIN TRANSACTION
UPDATE tblInventory
SET ItemsInStock = 8 WHERE Id = 1
COMMIT TRANSACTION
During transaction 1 UPDATE, transaction 2 can return the committed data in the SELECT statement. However, UPDATE statement in transaction 2 will be blocked, as the transaction 1 committed, transaction 2 returns the error:
Msg 3960, Level 16, State 6, Line 47
Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table 'dbo.tblInventory' directly or indirectly in database 'AdventureWorks2019' to update, delete,
or insert the row that has been modified or deleted by another transaction. Retry the transaction or change the isolation level for the update/delete statement.
During transaction 1 SELECT, transaction 2 can SELECT and UPDATE successfully.
Change Snapshot Isolation level ON & Read Committed Snapshot ON:
ALTER DATABASE AdventureWorks2019
SET ALLOW_SNAPSHOT_ISOLATION ON
ALTER DATABASE AdventureWorks2019 SET READ_COMMITTED_SNAPSHOT ON
I performed the same test above with the new database settings and it yields the same behaviors.
Can someone please helps me to understand the differences between (Snapshot Isolation level ON & Read Committed Snapshot OFF) and (Snapshot Isolation level ON & Read Committed Snapshot ON) in SQL Server?