by
0
6
3,079
1
Top 1% !
Popular
Famous
Specified
Refined
OpenSource
Popularity: 4483rd place
Created
Modified Jul 31, 2013
No tags for this snippet yet.
Architecturex86_64
DBMSMS SQL Server
LanguageSQL
LicenseMIT_X11
OSWindows
SQLServer Version2012
Windows VersionWindows7

Safe creation of Stored Procedure for MS SQL Server 2012

The following example of Stored Procedure can be use as a template for the creation of every procedure that needs a transaction
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/6240/Safe-creation-of-Stored-Procedure-for-MS?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
CREATE PROCEDURE [dbo].[TblName_ProcName] @Param1 nvarchar(50) AS BEGIN SET NOCOUNT ON; SET TRANSACTION ISOLATION LEVEL READ COMMITTED; SET XACT_ABORT ON; DECLARE @error int = 0; BEGIN TRAN -- do stuff; for each SQL instruction add the following statement to -- check the occurrence of an error: SET @error = @error + @@ERROR IF @error = 0 BEGIN COMMIT; RETURN 0; END ROLLBACK RETURN -1; END GO
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus