Using SQL Server as a DB queue with multiple clients

前端 未结 7 976
生来不讨喜
生来不讨喜 2020-12-04 08:06

Given a table that is acting as a queue, how can I best configure the table/queries so that multiple clients process from the queue concurrently?

For example, the ta

相关标签:
7条回答
  • 2020-12-04 09:02

    If you want to serialize your operations for multiple clients, you can simply use application locks.

    BEGIN TRANSACTION
    
    EXEC  sp_getapplock @resource = 'app_token', @lockMode = 'Exclusive'
    
    -- perform operation
    
    EXEC  sp_releaseapplock @resource = 'app_token'
    
    COMMIT TRANSACTION
    
    0 讨论(0)
提交回复
热议问题