Transaction count is stored incorrectly in the table

yashwin g shetty 20 Reputation points
Since session is not under transaction control i am expecting to be 0. If we use Variable to store @@Tran count and then insert it works fine.

note: If transaction count is more than 2 then it stores count of active transactions + 1

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
10,896 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 87,171 Reputation points

    You mean that you are doing something like:

    INSERT tbl (val) VALUES(@@trancount)

    Since the INSERT statement defines a transaction even if there is no user transaction, the expected value for @@trancount is 1, but if memory serves you get two for some reason.

0 additional answers

Sort by: Most helpful