S
S
Sergey Ivanchenko2017-12-28 17:24:34
MySQL
Sergey Ivanchenko, 2017-12-28 17:24:34

How to guarantee to get a new record in a MySql query inside a transaction?

Good afternoon. Tell me how in a transaction in MySQL it is guaranteed to get a record that is created in an insert.
Example:
1) I start a transaction
2) I create a record after 3) I read I get an empty list 4) I read it again in a second, there is a record How to get the created record at the 3rd step INSERT INTO Customers ( code ) VALUES (155);
SELECT * FROM Customers WHERE code=155;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2017-12-28
@ThunderCat

after the transaction, request LAST_INSERT_ID, and already use it for sampling

B
Boris Korobkov, 2017-12-28
@BorisKorobkov

2) I create a record through INSERT INTO Customers ( code ) VALUES (155);
3) Reading SELECT * FROM Customers WHERE code=155;
I get an empty list

This is possible only if step 3 is performed from another connection.
Enter a code.

R
RidgeA, 2017-12-28
@RidgeA

change transaction isolation level
https://dev.mysql.com/doc/refman/5.7/en/innodb-tra...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question