Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    51

    Unanswered: to give a table lock

    How can i give a table wise exclusive lock in MSSQL Server ?

    I got the description but, How can I apply this ?
    The sql :
    LOCK TABLE <tablename> IN EXCLUSIVE MODE
    is not working.

    Is there any query/method to do this ?
    Please help ...

    thanks


    About Exclusive locks
    --------------------
    Exclusive (X) locks are used for data modification operations, such as UPDATE, INSERT, or DELETE.

    Other transactions cannot read or modify data locked with an Exclusive (X) lock. If a Shared (S) exists, other transactions cannot acquire an Exclusive (X) lock.
    --------------------

  2. #2
    Join Date
    May 2002
    Posts
    299
    Code:
    declare @i int
    begin tran
    select @i=1
    from tb with (tablockx)
    
    -- the lock is not released until the tran
    -- is committed/rolled back.
    
    -- commit tran
    --
    -oj
    http://www.rac4sql.net

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd give some serious thought to what you are trying to do... This effectively puts the database into SINGLE USER mode, at least as far as that table is concerned. This is a really bad idea!

    -PatP

Posting Permissions

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