Manual SQL table lock

  •  

        Does anybody knows if is possible in MS-SQL 2K to manually setup and exclusive lock for a table?  I know about the query hints like HOLDLOCK, UPDLOCK, etc but according to Books online the query optimizer not necessarily will use those hints. 

     

  • Just use

    Begin Tran and Commit Tran

  • BEGIN TRAN

    update tablename with (HOLDLOCK)

    set somecolumn = 'X' WHERE anycolumn = nopossiblematch

     

    and then don't issue a commit tran

    but the bigger question is why or what are you really trying to do?

  • John:

    This is an Ad Hoc application (more like a group of Scripts) that updates the records in a specific table.  The scripts take a snapshot of the table and update the records base of this snapshot.

     My initial suggestion was to  run the update out of normal business hours, but apparently that is not possible due to schedule conflicts with other maintenance jobs and other reasons.

     The problem is that some times there are users in the system because they are suppose to have read access while this process is running.  The lock only have to be hold until all the records update is done.

    I was think that a UPDLOCK my work in this case.

     

    Thank You,

      Rafael

     

Viewing 5 posts - 1 through 4 (of 4 total)

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