|
example:
begin transaction
update storage
set Quantity = (Quantity-@insertquantity)
where storageid = @storageid
select @updatestor_error = @@ ERROR
Ransom
update RealStocking
set Quantity = (Quantity-@insertquantity)
where Stockingid = @stockingid
Ransom
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
Since I'm new to business, I have a few questions that I don't quite understand. I would like to ask.
1. I read some articles saying that if a transaction has been committed or rolled back, the following statements will continue.
Well, in the above example. If it is the end of the commit transaction, the subsequent else will continue to be judged. But the conditions do not meet the statement is not executed, is this so?
2. If the commit transaction ends, then the rollback transaction in ELSE is the corresponding begin transaction? Is the commit transaction over? SQL SERVER will automatically add an invisible begin transaction to correspond to the rollback transaction. .Thank you |
|