Quantcast
Channel: Transaction basics. What is the result of 2 transactions running concurrently? - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 3

Transaction basics. What is the result of 2 transactions running concurrently?

$
0
0

I have a rather basic question on transactions.
Assume a table Account with a column amount. Now we have the following code:

BEGIN  $amount = SELECT amount FROM ACCOUNT WHERE id = 123;  $amount = $amount - 100;  UPDATE ACCOUNT SET amount = $amount WHERE id = 123;    COMMIT

Now if this snippet runs concurrently by 2 transactions, T1 and T2 what will happen?
I know that in MySQL by default the isolation level is REPEATABLE READ.
So let's say that amount initially is 500.
So when the 2 transactions finish will the final amount be 300 or 100?
I mean when they start both read from table which I guess is a shared lock.
When one updates the table it gets an exclusive lock right? So what happens to the other transaction? Will it proceed with the amount it "view" when it started i.e. 500?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images