How do you lock tables in SQL Server 2005, and should I even do it?

后端 未结 7 1956
醉话见心
醉话见心 2021-02-19 15:35

This one will take some explaining. What I\'ve done is create a specific custom message queue in SQL Server 2005. I have a table with messages that contain timestamps for both a

7条回答
  •  猫巷女王i
    2021-02-19 16:19

    Something like this

    --Grab the next message id
    begin tran
    declare @MessageId uniqueidentifier
    select top 1 @MessageId =   ActionMessageId from UnacknowledgedDemands with(holdlock, updlock);
    
    --Acknowledge the message
    update ActionMessages
    set AcknowledgedTime = getdate()
    where ActionMessageId = @MessageId
    
    -- some error checking
    commit tran
    
    --Select the entire message
    ...
    ...
    

提交回复
热议问题