to do it the hardway, you have to check @@error after each update/insert: each command changes the @@error:
ALTER procedure MyProc
As
BEGIN
begin transaction
update1
if @@error != 0 GOTO Bailout
update2
if @@error != 0 GOTO Bailout
insert1
if @@error != 0 GOTO Bailout
insert2
if @@error != 0 GOTO Bailout
commit transaction
return 0 --by returning, no lines below this point will be executed UNLESS sent there directly by the GOTO command
Bailout:
print 'Error!'
rollback transaction
return 1
END
begin transaction
update1
if @@error != 0 GOTO Bailout
update2
insert1
insert2
Bailout:
commmit transaction
pedro.ribeiro (4/1/2009)
Ok. I understud very well tks.sorry to take your time, colud you explain me how to do this but without the Xact_abort? so that i can learn the two ways?
I think that if i do like:
begin transaction
update1
update2
insert1
insert2
commmit transaction
if @@error <> 0 then
roolback transaction
It functions too. is this correct?
Or will the @@error only detect errors inn the last instructuction (insert 2) and it only roolback that last insert?
tks,
Pedro
Lowell