@@TRANCOUNT 和当前连接

@@TRANCOUNT and a current connection(@@TRANCOUNT 和当前连接)
本文介绍了@@TRANCOUNT 和当前连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

假设我通过 SQL Server Management Studio ( SSMS ) 连接到 SQL Server 2008 并通过单击新建查询"选项卡打开新窗口 W1 并在 W1 中写入以下内容:

Assume I connect to SQL server 2008 via SQL Server Management Studio ( SSMS ) and open new window W1 by clicking on New Query tab and write the following inside W1:

BEGIN TRANSACTION;

如果我执行这个语句5次,然后写(在W1里面)

If I execute this statement 5 times, and then write (inside W1)

SELECT @@TRANCOUNT;

,那么返回的值将是 5.但是如果我打开另一个窗口 W2(在同一个 SSMS 实例内,因此在同一个连接上)并在 W2 内写入

, then the value returned will be 5. But if I open another window W2 ( inside the same SSMS instance and thus on the same connection ) and write inside W2

SELECT @@TRANCOUNT; 

那么返回的值为 0.

@@TRANCOUNT 变量返回当前连接的活动事务数.

@@TRANCOUNT variable returns the number of active transactions for the current connection.

W1 和 W2 窗口都在同一个连接上打开,所以不应该(根据上面的引用)在 W1W2 变量 @@TRANCOUNT 中保持相同的价值?

Both W1 and W2 windows were opened on the same connection, so shouldn’t ( according to the above quote ) in both W1 and W2 variable @@TRANCOUNT hold the same value?

谢谢

推荐答案

SSMS 中的每个查询窗口都是一个单独连接,在单独的 spid 上运行.查询窗口选项卡中括号中的数字是您当前窗口的连接号.

Every query window in SSMS is a separate connection, running on a separate spid. The number in parenthesis in the query window tab is your connection number for the current window.

打开几个窗口,并根据需要在每个窗口中打开事务,您应该能够看到每个窗口都显示在调用 sp_who2 的结果中.使用窗口选项卡中的 spid 编号,您将能够在该过程的结果中找到每一行.您还可以在每个查询窗口底部的状态栏中以及每个打开的查询窗口的属性窗口中找到有关您的连接的详细信息.

With a couple windows open, and open transactions in each if you like, you should be able to see each one of them show up in the results of a call to sp_who2. Using the spid number from the window tab you'll be able to find each row in the results of that proc. You can also find detailed information about your connection in the status bar at the bottom of each query window, and also in the properties window for each open query window.

这篇关于@@TRANCOUNT 和当前连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
SQL query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)