Absolutely. A rollback transaction rolls back to the outer most
transaction. The inner transactions really don't do anything at all, except
increment @@TRANCOUNT. If you want to be able to roll back part of a
transaction, use SAVE TRANSACTION savepoint/ROLLBACK TRANSACTION savepoint.
Both methods have the same results. The one exception is if BOOM! happens
in Inner transaction A, then Inner transaction B will commit, and the final
COMMIT statement will cause an error to occur. The same is true if BOOM!
happens in sp1. That's why you should always, always, always check @@ERROR
after every INSERT/UPDATE/DELETE statement in a stored procedure or query
batch.
[quoted text, click to view] "Mike Labosh" <mlabosh@hotmail.com> wrote in message
news:OgqEYzEfFHA.3916@tk2msftngp13.phx.gbl...
> Let's say I have a big fat SP that goes something like this:
>
> BEGIN TRANSACTION
> -- Outer transaction
>
> -- Do some stuff.
>
> BEGIN TRANSACTION
> -- Inner Transaction 'A': Do other Stuff
> COMMIT TRANSACTION
>
> BEGIN TRANSACTION
> -- Inner Transaction 'B': Do More Stuff
> COMMIT TRANSACTION
>
> -- Try to do some more stuff
> -- BOOM! Primary Key Violation causes Rollback
>
> COMMIT TRANSACTION
>
> Will transactions A and B also be rolled back?
>
> Also, what if it goes like this:
>
> BEGIN TRANSACTION
> -- Do some stuff.
> EXEC sp1
> EXEC sp2
> -- Try to do some more stuff
> -- BOOM! Primary Key Violation causes Rollback
> COMMIT TRANSACTION
>
> And sp1 & sp2 both have a BEGIN TRAN / COMMIT TRAN block in them. Same
> behavior as the first example?
> --
> Peace & happy computing,
>
> Mike Labosh, MCSD
>
> "Mr. McKittrick, after very careful consideration, I have
> come to the conclusion that this new system SUCKS."
> -- General Barringer, "War Games"
>
>