OK, when you said FIFO before, then we all went in that direction. What it
appears that you have is multiple threads doing inserts and only one thread
doing deletes. Your determination of what is the first to be deleted can be
done based on a datetime column. Bear in mind that it is possible to have
more than one row with the same datetime value, so use a SELECT TOP 1. It
is possible to do the delete of the so-called first row and manage the
processing via a trigger. Failing that, you can do a select inside a
transaction to get the row but maintain the lock on that row until the
commit, as was shown in another post.
--
Tom
----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
..
[quoted text, click to view] "Spam Catcher" <spamhoneypot@rogers.com> wrote in message
news:Xns98E4E5DAE74C6usenethoneypotrogers@127.0.0.1...
"Stefan Delmarco" <StefanDeOnline@fotia.co.uk> wrote in
news:ua4yGUsWHHA.1000@TK2MSFTNGP05.phx.gbl:
[quoted text, click to view] >
> It's easy to see why this works so well. Don't be tempted to replace
> the SELECT...DELETE logic with a status column. You'll have deadlock /
> concurrency problems under load, guaranteed.
Thanks for the tip - it looks great.
When you mean replace with a status column, do you mean I need to delete
the record outright from the queue?
Also, would your query work if I need to do the queue selection based on a
couple criterias (i.e. oldest record first, perhaps 1 or 2 other
criterias)?
I guess I shouldn't have said "FIFO" since it's not true FIFO, but rather I
only want the ability to select the "next pending record" once (i.e. single
thread the reads).