|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Tuesday, January 11, 2011 5:06 AM
Points: 54,
Visits: 32
|
|
Hi,
When i execute the following Script. I get error 'Cannot roll back InnerTran. No transaction or savepoint of that name was found.' i.e I couldn't able to rollback inner transaction. Can any one know the reason for this?
Create Table BPTest(id int) begin try begin tran OuterTran Insert into BPTest values (1) begin try begin tran InnerTran Insert into BPTest values (2) Declare @Error varchar(500) set @Error='test' RAISERROR(@Error, 16, -1) commit tran InnerTran end try begin catch rollback tran InnerTran end catch Insert into BPTest values (3) rollback tran OuterTran end try begin catch print Error_Message() end catch Select * from BPTest drop table BPTest Thanks in advance, Regards, B. Prakash
To Get Succeeded in Life don't get Changed according to the environment, Be Honest, Smart & Bold enough to create your own fine environment. Regards, B.Prakash.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,732,
Visits: 23,078
|
|
I think you want to use a transaction save point:
Create Table #BPTest(id int) begin try begin tran OuterTran Insert into #BPTest values (1) begin try save tran InnerTran Insert into #BPTest values (2) Declare @Error varchar(500) set @Error='test' RAISERROR(@Error, 16, -1) end try begin catch rollback tran InnerTran end catch Insert into #BPTest values (3) end try begin catch print Error_Message() rollback tran OuterTran end catch Select * from #BPTest drop table #BPTest
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, March 25, 2013 12:17 AM
Points: 18,
Visits: 38
|
|
So we cannot have nested Transactions (it does not make any sense to have nested transaction when we are not allowed to rollback the inner transaction) in SQL Server? And if we want nested transaction we should use Save Point instead?
In other words in SQL Server nested transactions can be implemented by using Save Points? Kindly explain this.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:11 PM
Points: 37,741,
Visits: 30,020
|
|
|
|
|