R
R
ReginaStart2021-01-24 14:40:51
SQL
ReginaStart, 2021-01-24 14:40:51

How to write consecutive max+1 values ​​in SQL without data duplication?

Good afternoon , laravel has a model with a table,

Tickets:
- cabinet_id
- number
- time

entry at number 10, then the new entry will be at number 11 (and if it has exceeded 999 we assign 1) , and everything works fine, but if we send 2 requests almost simultaneously, with a difference of less than 1 second, we can get the result as:

10 , 11, 11, 11, 12, 13

I understand that this is due to the fact that requests are executed in parallel, and at the time of the selection, record 11 does not yet exist, and each request thinks that it can record this parameter, but as a result, several different records with the same number are created, how to avoid this in Larave duplication? AI, as I understand it, is not particularly suitable for this, since entry 11 may be in cabinet A, B, C, as well as periodically repeated when the counter is reset.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question