May 12, 2008 at 9:48 am
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.
May 12, 2008 at 1:08 pm
I think you want to use a transaction save point:
[font="Courier New"]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 [/font]
January 31, 2011 at 4:29 am
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.
January 31, 2011 at 4:42 am
Nested transactions are a lie.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply