Friday, 19 February 2010

TRY / CATCH with rollback

A simple template for a TRY/CATCH block implementing a rollback if the statements fail.
BEGIN TRY
  BEGIN TRANSACTION     
  -- DELETE STATEMENT  
  -- INSERT STATEMENT
  COMMIT     
END TRY

BEGIN CATCH
  IF @@TRANCOUNT > 0
     ROLLBACK
END CATCH

Links :
Four guys from rolla
Solace : Try/Catch Error Detection

No comments: