Transaction count is stored incorrectly in the table

Yashwin G Shetty 40 Reputation points
2023-08-30T15:58:34.2166667+00:00
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 | Other
{count} votes

Accepted answer
  1. Erland Sommarskog 122K Reputation points MVP Volunteer Moderator
    2023-08-30T21:49:48.1933333+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.