zoukankan      html  css  js  c++  java
  • 存储过程模板(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
    

      

  • 相关阅读:
    随笔2
    随笔
    关于updateElement接口
    随笔1
    本地访问正常,服务器访问乱码 记录
    Redis (error) NOAUTH Authentication required.解决方法
    tomcat启动很慢 停留在 At least one JAR was scanned for TLDs yet contained no TLDs.
    微信公众号消息回复
    微信公众号 报token验证失败
    idea中web.xml报错 Servlet should have a mapping
  • 原文地址:https://www.cnblogs.com/tewuapple/p/2577226.html
Copyright © 2011-2022 走看看