When you use nested sp with transactions, that is you using nested transaction. When use nested transactions without name it, when you call rollback tran, it will rollback the outer most transaction. So it set @@TranCount to 0. You can try the code below to test:
begin tran
print @@trancount
begin tran
print @@trancount
begin tran
print @@trancount
commit tran
print @@trancount
begin tran
print @@trancount
rollback tran
print @@trancount
You can't rollback (but commit OK) nested (inner) transaction with name. Because only the first (outermost) transaction is registered with the system. A rollback to any other name (other than a valid savepoint name) generates an error.
Test this code:begin tran T1
print @@trancount
begin tran T2
print @@trancount
begin tran T3print @@trancount
commit tran T3 --OK
print @@trancount
rollback tran T2 --Error
print @@trancount
So, if you want to rollback at inner trans, use :
SAVE TRANSACTION MyName
6 comments:
It is remarkable, a useful piece
I wish not approve on it. I assume nice post. Expressly the designation attracted me to study the unscathed story.
Genial fill someone in on and this fill someone in on helped me alot in my college assignement. Say thank you you for your information.
Genial brief and this post helped me alot in my college assignement. Thank you seeking your information.
Brim over I to but I think the collection should prepare more info then it has.
Amiable brief and this enter helped me alot in my college assignement. Thanks you for your information.
Post a Comment