Sql-server – Is it possible to override a ReadCommittedSnapshot isolation level with ReadCommitted isolation level for a particular transaction

isolation-levelsnapshot-isolationsql server

The default isolation level of my database is "read committed snapshot". Please see the below screenshot.

read committed snapshot

I have the table "Tickets' with the following data in my database.

enter image description here

Now in connection 1, I am starting a new transaction with isolation level as "read committed". And I'm going to update the priority to 'medium' for the #TicketID "2"

enter image description here

From Connection 2, I am trying to access the details of #TicketID "2". And its still taking the value from the version store which is created by the read committed snapshot isolation, which is not expected behavior.

enter image description here

As per documentation, if a transaction using "read committed" isolation level, the row can't be accessed by any other transaction until the transaction performs a commit/Rollback.

Can anyone tell me why it is not happening in the given scenario? I am also curious to know, why a transaction level isolation is not able to override the default isolation level (here read committed snapshot) which is set at the database level?


To give more clarity on the isolation override on the transaction scope, I'm providing the below information.

I have set my database isolation to read committed.

enter image description here

Now in connection 1, I am initiating my transaction to update the Tickets priority.

enter image description here

In connection 2, I am trying to access the record. But this will not complete since the transaction isolation level is in "read committed" mode.

enter image description here

In connection 3, I am trying to access the record with isolation level as "read uncommitted". Here we can see the record as since it will override the default isolation which is set at the database level.

enter image description here

I am expecting the same behavior when I set "Snapshot Isolation" at the database level, and overide it in another transaction scope. For me, it always returns the last committed value from the version store irrespective of the isolation level which is mentioned at the transaction scope. I hope I conveyed my concerns clearly.. 🙂

Best Answer

There is no way to override the database-level setting of read committed snapshot (RCSI) for a whole transaction.

When RCSI is set, all read committed transactions will use row versions, delivering the last committed version of a row.

A session-level override option has been asked for. You can vote for it on the product feedback site at Add SET TRANSACTION ISOLATION LEVEL READ COMMITTED LOCK.

You can override the setting per-statement and per-table using the READCOMMITTEDLOCK table hint.

Alternatively, you could use snapshot isolation (SI) and turn read committed snapshot isolation (RCSI) off. Each transaction would then either SET TRANSACTION ISOLATION SNAPSHOT or SET TRANSACTION ISOLATION LEVEL READ COMMITTED.

More information in my series of articles on isolation levels.