sql事物
declare @iErrorCount int set @iErrorCount = 0 begin tran Tran1 insert into t1(Id, c1) values(1,'1') set @iErrorCount=@iErrorCount+@@error insert into t1(Id, c1) values('XX2','2') set @iErrorCount=@iErrorCount+@@error if @iErrorCount=0 begin COMMIT TRAN Tran1 --执行事务 end else begin ROLLBACK TRAN Tran1 --回滚事务 end
declare
@iErrorCount
int
set
@iErrorCount = 0
begin
tran Tran1
insert
into
t1(Id, c1)
values
(1,
'1'
)
set
@iErrorCount=@iErrorCount+@@error
insert
into
t1(Id, c1)
values
(
'XX2'
,
'2'
)
set
@iErrorCount=@iErrorCount+@@error
if @iErrorCount=0
begin
COMMIT
TRAN Tran1
--执行事务
end
else
begin
ROLLBACK
TRAN Tran1
--回滚事务
end