SET XACT_ABORT on
BEGIN TRAN
INSERT INTO [PDA_Action] VALUES (‘采购入库1‘)
INSERT INTO [PDA_Action] VALUES (‘采购入库2‘)
SELECT 1/0 /* 除数为0错误 */
INSERT INTO [PDA_Action] VALUES (‘采购入库3‘)
INSERT INTO [PDA_Action] VALUES (‘采购入库4‘)
COMMIT TRAN
对于有select的语句的回滚,用下面这种
Begin Try
Begin Tran Tran1
INSERT INTO [PDA_Action] VALUES (‘采购入库1‘)
INSERT INTO [PDA_Action] VALUES (‘采购入库2‘)
SELECT 1/0 /* 除数为0错误 */
INSERT INTO [PDA_Action] VALUES (‘采购入库3‘)
INSERT INTO [PDA_Action] VALUES (‘采购入库4‘)
COMMIT TRAN Tran1
END Try
Begin Catch
ROLLBACK TRAN Tran1 ---出错后调用回滚
--select 0
END Catch
原文地址:http://blog.csdn.net/anjoly/article/details/46340767