/*
CREATE TABLE [dbo].[t1](
[age] [int] NULL,
[name] [varchar](20) NULL
)ON [PRIMARY]
*/
---如果不设置该项为ON,在sql中默认为OFF,那么只只回滚产生错误的 Transact-SQL 语句;设为ON,回滚整个事务
SET
XACT_ABORT
ON
----语句产生运行时错误,则整个事务将终止并回滚。
Begin
Tran
INSERT
INTO
t1(age,
name
)
VALUES
(1,
'1'
)
INSERT
INTO
t1(age,
name
)
VALUES
(
'XX2'
,
'2'
)
--此句产生错误时,就会回滚整个事务
Commit
Tran