Is it okay if from within one stored procedure I call another one that sets a lower transaction isolation level?

空扰寡人 提交于 2019-12-06 03:51:29

It's all here for SQL Server 2005. A snippet:

When you change a transaction from one isolation level to another, resources that are read after the change are protected according to the rules of the new level. Resources that are read before the change continue to be protected according to the rules of the previous level. For example, if a transaction changed from READ COMMITTED to SERIALIZABLE, the shared locks acquired after the change are now held until the end of the transaction.

If you issue SET TRANSACTION ISOLATION LEVEL in a stored procedure or trigger, when the object returns control the isolation level is reset to the level in effect when the object was invoked. For example, if you set REPEATABLE READ in a batch, and the batch then calls a stored procedure that sets the isolation level to SERIALIZABLE, the isolation level setting reverts to REPEATABLE READ when the stored procedure returns control to the batch.

In this example:

  • Each isolation level is applied for the scope of the stored proc
  • Resources locked by DoSomethingImportant stay under SERIALIZABLE
  • Resources used by CheckSomething are READ UNCOMMITTED
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!