• 存储过程模板(StoredProc+Template)


    create/alter procedure <SP Name>
    
    /*---------------------------------------------------------------------------
    DESCRIPTION:
    This procedure will get the list of users.
    
    AUTHOR:	
    DATE:
    
    PARAMETERS:
    Parameter 1: Description of parameter1 
    Parameter 2: Description of parameter2
    
    RETURN VALUE:
    
    AFFECTED TABLES:
    Table1
    Table2
    ---------------------------------------------------------------------------*/
    
    @DiscussionID uniqueidentifier
    ...
    as
    
    begin
    
          -- other declare statements
    
          declare @Error int
    
          declare @TrCount tinyint
    
     
    
          -- other set statements
    
          set @Error = 0
    
          set @TrCount = @@trancount
    
     
    
          -- other core/main logic Example1...
    
          select @Error = @@error, @RowCount = @@rowcount
    
          if (@Error <> 0) goto error
    
     
    
          -- other core/main logic Example 2...
    
          if (@RowCount = 0) 
    
                begin set @Error = <some sysmessage error#> raiserror (@Error, 16, 1) goto error end
    
     
    
          -- other core/main logic Example 3...
    
          if @Error <> 0 
    
                begin raiserror(@Error, 16, 1) goto error end
    
     
    
          -- should be last statements after processing all other logic
    
          if @@trancount > @TrCount 
    
          commit transaction
    
          goto conclude
    
     
    
          -- other logic...
    
     
    
          error:
    
                if @@trancount > @TrCount 
    
                      rollback transaction
    
     
    
          conclude:
    
                -- anything that needs to be undone like cleanup, drop temp tables, etc.
    
                -- set flags need to be reset, for example 'set nocount off'
    
                -- prepare output parameters if any
    
                -- other xml output for return if any, for example ‘select @Error RetCode for xml raw’
    
          return @Error
    
    end
     
    go
    

      

  • 相关阅读:
    if 语句运用
    c#语言基础
    关于条件运算符的应用
    Could not open Hibernate Session for transaction;
    node to traverse cannot be null!
    Struts2文件下载中文名乱码
    Spring MVC框架下的第一个Hello World程序
    strtus2中的defaultactionref无效的解决方法
    c 笔记
    工具系列1
  • 原文地址:https://www.cnblogs.com/tewuapple/p/2577226.html
Copyright © 2020-2023  润新知