0

When using snapshot isolation, why do I often see IF @@TRANCOUNT = 0 before setting the transaction level?

I.e., in a stored proc:

IF @@TRANCOUNT = 0
BEGIN
    SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
END
Hoppe
  • 6,508
  • 17
  • 60
  • 114

1 Answers1

2

one reason is this from Microsoft Documentations:

A transaction cannot be set to SNAPSHOT isolation level that started with another isolation level; doing so will cause the transaction to abort. If a transaction starts in the SNAPSHOT isolation level, you can change it to another isolation level and then back to SNAPSHOT. A transaction starts the first time it accesses data.

eshirvana
  • 23,227
  • 3
  • 22
  • 38