在 SQL Server 中,我如何知道我当前使用的是哪种事务模式? [英] In SQL Server, how do I know what transaction mode I'm currently using?

查看:29
本文介绍了在 SQL Server 中,我如何知道我当前使用的是哪种事务模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 SQL Server 中,我如何知道我当前使用的是哪种事务模式?例如自动提交、显式或隐式.以及如何使用 tsql 将一种模式更改为另一种模式?非常感谢.

In SQL Server, how do I know what transaction mode I'm currently using? Such as autocommit, explicit, or implicit. And how can I change one mode to another using tsql? Great thanks.

推荐答案

IF @@TRANCOUNT = 0 PRINT 'No current transaction, autocommit mode (default)'
ELSE IF @@OPTIONS & 2 = 0 PRINT 'Implicit transactions is off, explicit transaction is currently running'
ELSE PRINT 'Implicit transactions is on, implicit or explicit transaction is currently running'

我认为没有办法确定当前事务是显式启动还是隐式启动.因此,这段代码只是尝试猜测:如果 IMPLICIT_TRANSACTIONS 为 OFF,则假定事务已显式启动.

I don't think there is a way to determine whether current transaction was started explicitly or implicitly. So, this code just tries to guess: if IMPLICIT_TRANSACTIONS is OFF, the transaction is assumed to be started explicitly.

MSDN 参考资料:

这篇关于在 SQL Server 中,我如何知道我当前使用的是哪种事务模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆