zoukankan      html  css  js  c++  java
  • sqlserver存储过程事务回滚

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    
    
    ALTER PROCEDURE [dbo].[AddUserOnChannel]
    @UserName varchar(50),
    @Password varchar(50),
    @ChannelID int,
    @Lock bit,
    @Remark text,
    @rtn int output--1成功-1失败
    AS
    BEGIN
            declare @UserID int
            declare @tran varchar(50)
            set @rtn=-1;
            set @tran='1234'
    begin tran  @tran
                begin try
    --插入用户信息
                     insert into [User]
                    (UserName,Password,Remark,Lock)
                    values
                    (
                    @UserName,
                    @Password,
                    @Remark,
                    @Lock
                     );
    --查找用户ID
                    select @UserID=ID from [User] where userName=@UserName;
    --插入UserChannel表数据
                    insert into UserChannel
                    (
                    UserID,
                    ChannelID
                    )
                    values
                    (
                    @UserID,
                    @ChannelID
                    )
                   set @rtn=1;
               end try
               begin catch
                  if @@trancount>0
                    rollback tran  @tran;
               end catch
                  if @@trancount>0
                    commit tran  @tran;
    END

    感谢田老表...

  • 相关阅读:
    POJ
    CodeForces
    部分和问题
    NOIP200502校门外的树
    消灭虫子
    抓牛
    最长不下降子序列的长度
    HDNoip201501计算结果最小
    抽签
    Ants
  • 原文地址:https://www.cnblogs.com/qq1223558/p/3477986.html
Copyright © 2011-2022 走看看