标签:
begin try begin transaction --开始事务 DECLARE @myMemberID NVARCHAR(36) ,--用户ID @myBizID NVARCHAR(36) , @myBizType NVARCHAR(36) --业务ID SET @myMemberID = ‘2‘ SET @myBizID = ‘2‘ SET @myBizType = ‘2‘ IF EXISTS ( SELECT 1 FROM D_MemberAdmire WHERE MemberID = @myMemberID AND BizID = @myBizID ) UPDATE dbo.D_MemberAdmire SET IsDel = CASE WHEN IsDel = 1 THEN 0 ELSE 1 END WHERE MemberID = @myMemberID AND BizID = @myBizID; ELSE INSERT INTO D_MemberAdmire ( ID , BizType , BizID , MemberID , Status , IsDel ) VALUES ( NEWID() , @myBizType , @myBizID , @myMemberID , 1 , ‘a‘ ); --UPDATE dbo.D_MemberAdmire SET Status=‘a‘--测试语句 commit transaction --提交事务 end try begin catch --抓取异常 select ERROR_NUMBER() as errornumber --查询错误代码 rollback transaction --回滚事务 end catch
标签:
原文地址:http://www.cnblogs.com/xiaoshi657/p/5171071.html