@@Trancount

  • SELECT @@TranCount

    SELECT @@TranCount As A INTO #A

    SELECT * FROM #A

            SELECT @@TranCount

     

    Why I am getting 2 in the table, basically it is inserting 2 in the table inspite there is no transaction.

    I know I should assign the value to a variable and then insert .

    I am not looking for a solution but an explanation

    Amit

     


    Kindest Regards,

    Amit Lohia

  • OK disclaimer: I don't know

    But based on what I do know about SQL Server...

    Each statement is implicitly within a transaction.  That is that behind the curtain SQL is issuing a begin tran/commit-rollback around any INS/DEL/UPD/SEL statement. 

    So that would account for it being 1 greater than the first select @@trancount.

    Next I would guess that SQL2k treats the select into as a two step process way down deep: separating the select and the insert, which would account for the 2.

    That's my swag at it.

  • I know it's just an experiment but, ugh... if you end up counting transactions in your code, ya just might have a bigger problem with your application...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I guess you're connected using implicit transactions.

    (or use an oledb.begintran statement which switches your connection to "implicit transactions)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply