0

I started two transactions at same time in mysql.

After updating one transaction and commited it, in second transaction I still get the old value instead of updated value.

What is the reason for that?

I inserted a new row in to a table in T1.After commited the first transaction,Here in T2,it doesnt show the newly inserted row in T1(by select * from table command).Since i committed the first transaction shouldn't second transaction give the updated value?

T1
start transaction;
insert table1(id,name)values(5,'new name);
commit;

T2:
start transaction;(This transaction is started at the same time when t1 started.)
select * from table1;(this has done after commit the T1);

enter code here

  • Can you please expand? What were the transactions? What did you check? – Uberhumus May 25 '20 at 20:11
  • @Uberhumus sure.I have edited my question.Thank You! – user13615162 May 26 '20 at 14:20
  • I think you might need to re-edit. I doubt it looks like you intended. – Uberhumus May 26 '20 at 14:21
  • sorry for that.I have re edited.Im a beginner for this and sorry for the mistakes! – user13615162 May 26 '20 at 14:32
  • It's OK, this is how we learn. Now, as for the actual question, please explain how you know that the 2nd one isn't executed before the 1st one (In the answer). – Uberhumus May 26 '20 at 14:38
  • oh !!!it means we cant guarantee that which transaction is executed first in concurrent transactions?Therefore,we have to commit all transactions.is it? – user13615162 May 26 '20 at 14:44
  • You're in a good direction, now if I were you I would do a few things. I would time each transaction (several times if possible) to see which is quicker. If the 2nd transaction is repeatedly quicker you have your answer. If it's dynamic you can add a delay in the 2nd transaction. Also I would read more about SQL race conditions, over here for example https://stackoverflow.com/questions/6477574/do-database-transactions-prevent-race-conditions and then I would write an answer to my own question. :) – Uberhumus May 26 '20 at 15:03
  • @Uberhumus Thankyou very much for your kind guidelines!!!!Thank You again!!! – user13615162 May 26 '20 at 15:10

0 Answers0