码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver sp模板

时间:2014-10-23 12:21:08      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   log   

某公司内部的sp模板

create procedure [usp_my_procedure_name]
as
begin
    set nocount on;
    declare @trancount int;
    set @trancount = @@trancount;
    begin try
        if @trancount = 0
            begin transaction
        else
            save transaction usp_my_procedure_name;

        -- Do the actual work here

lbexit:
        if @trancount = 0
            commit;
    end try
    begin catch
        declare @error int, @message varchar(4000), @xstate int;
        select @error = ERROR_NUMBER(), @message = ERROR_MESSAGE(), @xstate = XACT_STATE();
        if @xstate = -1
            rollback;
        if @xstate = 1 and @trancount = 0
            rollback
        if @xstate = 1 and @trancount > 0
            rollback transaction usp_my_procedure_name;

        raiserror (usp_my_procedure_name: %d: %s, 16, 1, @error, @message) ;
    end catch
end

尾部

sqlserver sp模板

标签:style   blog   color   io   ar   sp   div   on   log   

原文地址:http://www.cnblogs.com/theonewu/p/4045277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!