I need to configure the queue system using some SQL tables, for example, described here . This, and since I need to filter queues in different criteria, inside the stored procedure I use
BEGIN TRANSACTION
CREATE TABLE
INSERT INTO
INSERT INTO
(...)
UPDATE TableB SET SomeField = 1 FROM TableB WITH (ROWLOCK, READPAST) WHERE ID IN (SELECT ID FROM
COMMIT TRANSACTION
I use ROWLOCKin the first table and UPDLOCKin the second, because after that select I am going to update only TableB, although I need to make sure that these rows are not updated in TableAany other parallel query. Everything goes well until I need to insert a sentence ORDER BYin any of the SELECTabove, so only very specific identifiers will be selected (I have to do this really). What's happening:
1) ORDER BY , ; , , SELECT.
2) ORDER BY , . .
, , WITH (ROWLOCK, READPAST) ORDER BY , . , . ?
: , TestTable (TestID INT, Value INT) "(1,1), (2,2),..." ""
BEGIN TRANSACTION
SELECT TOP 2 TestID FROM TestTable WITH (UPDLOCK, READPAST)
WAITFOR DELAY '00:00:05'
COMMIT TRANSACTION
(1,2), (3,4), . ,
BEGIN TRANSACTION
SELECT TOP 2 TestID FROM TestTable WITH (UPDLOCK, READPAST) ORDER BY VALUE ASC
WAITFOR DELAY '00:00:05'
COMMIT TRANSACTION
(1, 2), . ?!