Shura30,
You may find this article on queue based applications by Philipp Stiefel helpful for concept/background.
(same author as the Transaction article suggested by ebs17 in #31)
Great resource thanks, this is the exact scenario I need to address and it's literally the article, almost word for word
Looks like the UPDATE statement is the way to go
quotes from the article:
There should be only one table relevant for managing the queue. You can either put a LockUser- and LockTime-Field (more on the latter in a minute) right into the facts table (queue table) or you can create an additional table for managing the locks. That table would need those two fields and the primary key of the locked record. - There is not much difference between these two approaches.
Any number of users can read the same data from a database at the same time. So, when querying the next free record first and then locking the record, it is possible that two users query the same, not yet locked, record. There will be some latency between reading the record and writing the lock, so this might happen more often than you think.
To prevent this, you need to write the lock information first. That forces the database to serialize the operation. No two user will ever be able to lock the same record. Only read the record from the queue after locking it.