sql server - What will be the output of the following SQL Transaction ? -


identify output following code

print 'before transaction' select @@trancount begin tran t1 print 'after transaction t1 starts' /* value of @@trancount 1 */ select @@trancount begin tran t2 save tran t2 --save tran t2 print 'after transaction t2 starts' /* value of @@trancount 2 */ select @@trancount rollback tran t2 print 'after transaction t2 roll backs' /* value of @@trancount still 2 rollback failed due error */ select @@trancount ---------[it shoud 1,but why result coming 2?] rollback tran t1 print 'after transaction t1 roll backs' /* value of @@trancount 0 */ select @@trancount 

what reason improper output ?

answer lies in code, have used save tran t2, transaction t2 saved , rollback doesn't affect @@trancount value

try run below query multiple times in sql server....you see value of @@trancount gets increased 1, every time execute query.

select @@trancount begin tran t2 save tran t2 print 'after transaction t2 starts' select @@trancount rollback tran t2 print 'after transaction t2 roll backs' select @@trancount 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -