Created
September 16, 2011 14:52
-
-
Save dantuck/1222277 to your computer and use it in GitHub Desktop.
TSQL Transaction Management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @ERRORCODE INT | |
BEGIN TRANSACTION | |
-- do action | |
-- check for errors after each transaction if desired | |
SELECT @ERRORCODE = @@ERROR | |
IF (@ERRORCODE <> 0) GOTO PROBLEM | |
-- last statement before Problem resolution | |
COMMIT TRANSACTION | |
PROBLEM: | |
IF(@ERRORCODE <> 0 ) BEGIN | |
ROLLBACK TRANSACTION | |
-- Raise an error and return | |
RAISERROR ('Put your error response here', 16, 1) | |
RETURN | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment