存储过程错误事物回滚

	SET XACT_ABORT ON
	SET NOCOUNT ON 	
	SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
	
	DECLARE @intTranCount INT 
	SET @intTranCount=@@TranCount
	IF @intTranCount<> 0  SAVE TRANSACTION Savepoint ELSE BEGIN TRANSACTION 
	
	
	
	
	--错误提示--
		BEGIN 
			RAISERROR('存在重复的教师账号,请先把原账号停用后新增!',16,1)
			GOTO ErrHandle
		END 
		
		
		

	--完成--
	IF @intTranCount<>@@TranCount COMMIT TRANSACTION		 
	RETURN
	
ErrHandle:
	 IF @intTranCount=@@TranCount 
	BEGIN
		ROLLBACK TRANSACTION Savepoint 
		RETURN
	END
	ELSE
	BEGIN
		ROLLBACK TRANSACTION 
		RETURN
	END







	

  

posted @ 2017-10-23 14:01  贾梦阳1024  阅读(906)  评论(0编辑  收藏  举报