SQL locking and unlocking a row

  • Hi,

    How can i lock and unlock a table row. My application has been hosted and i want to lock a row so that it dont take the number if somebody else from other system is already using it.

    Please help me out,

    Thanks,

    Syed Tameemuddin

  • You can use Locking Hints (ROWLOCK). Check BOL for more details. But it is advised that you should let SQL Server itself manage the Locking.

    -Roy

  • I think you are trying to use a table to store some kind of progressive number incremented by every call to some kind of procedure, am I wrong?

    If so, UPDATE the table before selecting, the whole thing in a transaction:

    BEGIN TRANSACTION

    UPDATE myTable SET progNum = progNum + 1

    SELECT progNum - 1 AS progNum FROM myTable

    COMMIT TRANSACTION

    -- Gianluca Sartori

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply