SQL Server 出错自动回滚
转自:http://www.cnblogs.com/masterfy/archive/2009/04/09/1432283.html
ALTER procedure [dbo].[USP_DELETEMM_SBKP] (@ID INT) as
BEGIN
SET XACT_ABORT ON --只要出错就回滚
BEGIN TRAN--开始事务
……
--删除设备图片标签数据
DELETE A FROM CONFIGURATIONVIEW A WHERE EXISTS(SELECT 1 FROM CONFIGURATIONTREE B WHERE B.ParentNodeID=(@ID*100+1) AND A.NODEID=B.NODEID);
--删除设备
DELETE FROM MM_SBKP
WHERE ID = @ID;
COMMIT TRAN --提交事务
END
SET XACT_ABORT ON --只要出错就回滚 含义参见:
http://msdn.microsoft.com/zh-cn/library/ms188792.aspx