Showing posts with label Try Catch. Show all posts
Showing posts with label Try Catch. Show all posts

Thursday, January 14, 2016

How to create a Stored Procedure with Try Catch and Transaction

CREATE PROCEDURE dbo.spname
AS
BEGIN
BEGIN TRANSACTION;

BEGIN TRY

/*
YOUR COMMAND
/*

END TRY

BEGIN CATCH

IF @@TRANCOUNT > 0
       ROLLBACK TRANSACTION;
END CATCH;

IF @@TRANCOUNT > 0
   COMMIT TRANSACTION;


END;

Cheers!
Uma