Saturday, February 11, 2012

@@Trancount Error

Take a look a the sql code below. Can anyone explain why @.@.trancount increased to 2 after the 2nd print statement?

SETANSI_DEFAULTSON

GO

PRINT@.@.TRANCOUNT

GO

BEGINTRANSACTION

PRINT@.@.TRANCOUNT

GO

Here is the output I got

0

2

With the ANSI_DEFAULTS you also enable IMPLICIT_TRANSACTIONS. So executing a BEGIN TRAN actually starts a second transaction because your implicit transaction is 'open' although it only returns 1 for @.@.TRANCOUNT when you actually issue a query.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

No comments:

Post a Comment