CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008
    Posts
    5

    Table Lock in sql Server

    I have an issue regarding the table locks in sql server. Here is what i want to achieve :

    I have a table on a central database. 5 process from 5 different servers access this table through a stored procedure. Here is what the stored procedure do :

    Code:
    SELECT TOP 1 * FROM tbl_name WHERE Status = 0 ORDER BY id
    
    Do some checkings..(very small though)
    
    IF condition met:
          UPDATE tbl_name  SET Status = 1 Where id = (picked above)
    Else
          UPDATE tbl_name  SET Status = 2 Where id = (picked above)
    Now my concern is as all the 5 process from different servers access the same table, there might be a chance that when one process has taken a row and before it updates the Status to 1 or 2 another process might take the same row. So, i want to acquire a clock or something else on that table, so that everything is serial. Thanks.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Table Lock in sql Server

    Do you mean that "internal" lock mechanism of SQL Server doesn't work for you?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2011
    Posts
    61

    Re: Table Lock in sql Server

    put that in a transaction

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured