SQL存储过程--事务

	Create PROC [dbo].[AdDeleteAdMachineImgById]
	@AdMachineImgId VARCHAR(36)
	AS
	BEGIN TRAN
	DECLARE @errorSun INT --定义错误计时器
	SET @errorSun = 0
	UPDATE dbo.AdMachineImgs SET IsDeleted=1 WHERE AdMachineImgId=''+@AdMachineImgId+'' --删除资源(假删除)
	SET @errorSun = @errorSun + @@ERROR --累计错误次数
	
	DELETE FROM dbo.AdMachineImgRelaction WHERE AdMachineImgId=''+@AdMachineImgId+'' --删除资源关系(真删除)
	SET @errorSun = @errorSun + @@ERROR
	
	IF @errorSun <>0
	BEGIN
	ROLLBACK TRAN --有错误,回滚数据
	END
	ELSE
	BEGIN
	COMMIT TRAN --成功,提交数据
	END

  

posted @ 2017-03-16 09:55  蜗牛的礼物  阅读(106)  评论(0编辑  收藏  举报