Monday 24 March 2014

Nested Transaction in SQL Server 2012

Nested transaction is nothing but, you can make another transaction without even committing/Rollback previous transaction. With Every begin the value of @@Trancount increases by one and this is counter balanced by commit statement. As shown in image below. But in case of rollback it directly falls back to zero.

image

 

Lets experiment this;

Assume i have a table “Columns_for_Transaction_Example” having some values in it

image

Begin Nested Transaction:

image

here the value of Trancount will become 1. And new value would be like this as shown below

image

Let’s begin another transaction:

image

 

now Trancount will change to 2

image

 

lets check the value in table after the update, as  we can see offset value will become 0.

image

so now lets commit one by one , As shown in transaction tree figure trancount will decrease one by one ,can’t reduce to zero directly.

image

similarly if we do rollback,Trancount decreases directly to zero As shown below.

image

No comments:

Post a Comment