if @@Error<>0 --如果错误发生就会执行begin了 begin Rollback Tran Return -1 end
感觉应该判断写在前面!!!Create Proc spBuyBook( @iBookID int, @iOperatorID int ) As begin Begin Tran if @@Error<>0 goto Err_Handle Exec spDoSomething insert into ......... Commit Tran return 0 Err_Handle: begin Rollback Tran Return -1 end end
to 楼主:没有问题,可以回滚 示例 --测试数据 select top 3 * into ta from sysobjects go create proc sp_1 as delete ta where id=1 go --示例 begin tran exec sp_1 insert ta(name, id) select 'sysabc', 4 if @@error<>0 rollback tran else commit tran go select * from ta --清除 drop proc sp_1 drop table ta
begin
Rollback Tran
Return -1
end
@iBookID int,
@iOperatorID int
)
As
begin
Begin Tran
if @@Error<>0 goto Err_Handle
Exec spDoSomething
insert into ......... Commit Tran
return 0
Err_Handle:
begin
Rollback Tran
Return -1
end
end
示例
--测试数据
select top 3 * into ta from sysobjects
go
create proc sp_1
as
delete ta where id=1
go
--示例
begin tran
exec sp_1
insert ta(name, id) select 'sysabc', 4
if @@error<>0
rollback tran
else
commit tran
go
select * from ta
--清除
drop proc sp_1
drop table ta