Partial rollback doesn't decrement trancount Suppose I have an open SQL Server session, and do the following:

begin tran 

insert into People (Id) values (1)

select @@TRANCOUNT -- Prints 1

save transaction tt

begin tran

select @@TRANCOUNT -- Prints 2

insert into People (Id) values (2)


Ok, so now I make a:

rollback tran tt

select @@TRANCOUNT -- Prints 2!


My question is maybe obvious: 

Why partial rollback doesn't decrement @@TRANCOUNT increased by the inner transaction?

To commit changes I should do two commit commands. IMHO doesn't seems natural.
@@TRANCOUNT reports a count of BEGIN TRANSACTION statements, not active transactions. From a different perspective, it is reporting the depth of a nested transaction.


  @@TRANCOUNT (Transact-SQL)  Returns the number of BEGIN TRANSACTION
  statements that have occurred on the current connection. [source]


Misunderstandings of nested transactions and savepoint usage arise because nested transactions are not what we would expect them to be. To all intents and purposes there is no such thing as a nested transaction. The actions of a set of nested transactions are not committed until you issue the outer most COMMIT and a ROLLBACK will undo the actions of all. 

Nested transactions exist to support transactions in procedures which could be called from external processes that may have started a parent transaction, from parent procedures that may have done the same, or where no prior transaction exists. They do not provide nested commit and rollback behaviour.