Translate

Tuesday, June 12, 2012

SQL Server Try Catch and transaction Example




BEGIN TRY
BEGIN TRANSACTION

 --Update or Insert statements

COMMIT TRANSACTION
END TRY
BEGIN CATCH
 select ERROR_NUMBER() as ErrorNumber, ERROR_LINE() as ErrorLine, ERROR_MESSAGE() as ErrorMessage

IF (XACT_STATE()) <>
   BEGIN
     ROLLBACK TRANSACTION
   END

END CATCH

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator