@@TRANCOUNT 和当前连接

编程入门 行业动态 更新时间:2024-10-27 21:22:40
本文介绍了@@TRANCOUNT 和当前连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

假设我通过 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 和当前连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 20:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1195222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TRANCOUNT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!