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