我在存储过程里用BEGIN TRANSACTION
以下是begin tran和commit部分:begin tran
insert table1 ........
insert table2 ......
insert table3 ......
delete from table4......
delete from table5.....
update table 6
update table 6
commit我想请问一下:
1)以上的时务要么全部成功执行,要么全部不成功执行,是吗?
2)存储过程带有返回参数,如何把执行的结果通过参数返回?也就是如何才能得到成功执行或者不成功执行的信息?
以下是begin tran和commit部分:begin tran
insert table1 ........
insert table2 ......
insert table3 ......
delete from table4......
delete from table5.....
update table 6
update table 6
commit我想请问一下:
1)以上的时务要么全部成功执行,要么全部不成功执行,是吗?
2)存储过程带有返回参数,如何把执行的结果通过参数返回?也就是如何才能得到成功执行或者不成功执行的信息?
2、通过@@error判断
比如在以上的事务里,
update table 5 (不成功)
update table 6(成功)
那么在最后提取的@@error也是等于0。
as
begin tran
...
commit tran
set @err=@@error
ogdeclare @e int
exec tttt @e output
select @e
insert table1 ........
insert table2 ......
insert table3 ......
delete from table4......
delete from table5.....
update table 6
update table 6
commit这些中的SQL语句最好在执行每一条时进行@@error 判断, 要是错了跳转,因为要是第一条就错了下面的SQL执行还有意义吗