Hello, Tejaswini!
It's okay to be confused. Not a problem. I appreciate the fact that you asked for more clarification.
The point illustrated by #3 is, in itself the answer to #4.
Part #3 of this series illustrated that a rollback command will rollback the transactions all the way to the outermost transaction. However, this does not mean that one cannot have logical "save points" that allow you to rollback to the most recent/outermost save point, provided the rollback is a conditional rollback. Without a save point, the rollback must go all the way to the outermost transaction - with named transactions, you cannot rollback to an inner transaction without a save point. That is the point illustrated by part #4.
Hence, the following would have worked with respect to Part #4
CREATE TABLE MyTable (MyId INT IDENTITY (1,1),
MyCity NVARCHAR(50))
BEGIN TRANSACTION OuterTran
INSERT INTO MyTable VALUES ('Boston')
BEGIN TRAN InnerTran
INSERT INTO MyTable VALUES ('London')
SAVE TRAN InnerTran
INSERT INTO MyTable VALUES ('Paris')
SELECT *,'Post Save' FROM MyTable
ROLLBACK TRAN InnerTran
SELECT *,'Post Rollback Inner Transaction' FROM MyTable
ROLLBACK TRANSACTION OuterTran
SELECT *, 'Post Rollback Outer Transaction' FROM MyTable
DROP TABLE MyTable
To get more clarity, what I would recommend is to play around with transactions for a while - there can be no better teacher than experience.
Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Follow me on
Twitter: @sqltwins