| |

VerySource

 Forgot password?
 Register
Search
View: 902|Reply: 5

Ask the basics of a business

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-7 12:20:02
| Show all posts |Read mode
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
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-1-7 16:45:01
| Show all posts
The first problem has nothing to do with transactions, it is the problem of if statements
The second problem is that as long as the transaction is committed or rolled back, the transaction is complete
Reply

Use magic Report

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Invalid IP Address

 Author| Post time: 2020-1-8 06:54:01
| Show all posts
declare @ number1 int
declare @ number2 int
set @ number1 = 1
set @ number2 = 2
begin transaction
select @ number1
rollback transaction
         select @ number2
commit transaction
Is that understandable? The above statements are wrong because the rollback transaction was executed first.
So the transaction has ended. And the subsequent commit transaction will not correspond to the new begin transaction (because the first begin transaction has ended), so the program will be wrong. Is this understood? Thank you
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-14 18:30:02
| Show all posts
You did n’t understand if else. I ’m also new to business, but I understand.
The first floor gives begin tran and rollback tran or begin tran and commit tran.

The upstairs commit tran does not have a corresponding begin tran.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 09:00:01
| Show all posts
if commit else rollback normal logic
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-9-5 09:15:01
| Show all posts
LZ seems to think things are complicated, in fact, it is the usual understanding and judgment of if else, it's just a matter of commit and rollback when the content of judgment is
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list