TRY...CATCH along with TRANSACTION

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 304
begin try
begin tran
insert into test_tran values(1)
insert into test_tran values(1)
insert into test_tran values(2)
commit tran
end try

begin catch
Rollback tran -- even though the first statement ran succesfully and second record insert causes exception the complete transaction will be rolled back.
print ' CATCH '
end catch

select * from test_tran

Comments or Responses

Login to post response