|
例:
begin transaction
update storage
set Quantity = (Quantity - @insertquantity)
where storageid = @storageid
select @updatestor_error = @@ERROR
update RealStocking
set Quantity = (Quantity - @insertquantity)
where Stockingid = @stockingid
select @updaterestoc_error = @@ERROR
if @updatestor_error = 0 and @updaterestoc_error = 0
begin
commit transaction
end
else
begin
if @updatestor_error <> 0
print 'an error occured during update storage.'
if @updaterestoc_error <> 0
print 'an error occured during update reakstocking.'
rollback transaction
end
由于刚接触事务,有几个问题不大明白,想请教一下.
1. 我看有些文章说.如果一个事务已commit或rollback结束了.后面的语句仍将继续.
那么,上面的例子中.如果是在commit transaction结束的.那后面的else还会继续被判断到.只不过条件不符合没有执行里面的语句,是这样吗?
2. 如果是在commit transaction结束的,那后面ELSE中的rollback transaction又是对应的那个begin transaction呢?是不是commit transaction结束了.SQL SERVER会自动加上一个看不见的begin transaction去对应rollback transaction呢.谢谢
|
|