select 语句默认是共享锁。即它执行时,不会阻碍其它事物对此表的任何操作。

解决方案 »

  1.   

    那如果操作的是同样的一批数据呢?有人在delete,有人select,会怎样?
      

  2.   

    delete时有排他锁,因为一个事务的排它锁与其它事务的共享模式锁不兼容,所以delete时,select发生锁等待
      

  3.   

    多谢,今天在网上看到一篇文章说为了提高delete及update等操作的性能,可以批量进行,如:
    --Set rowcount to 50000 to limit number of updates
    --performed in each batch to 50K rows.
    Set rowcount 50000--Declare variable for row count
    Declare @rc int
    Set @rc=50000While @rc=50000
     Begin  Begin Transaction  --Use tablockx and holdlock to obtain and hold 
      --an immediate exclusive table lock. This unusually
      --speeds the update because only one lock is needed.
      Update MyTable With (tablockx, holdlock)
        Set UpdFlag = 0
      From MyTable mt  --Get number of rows updated
      --Process will continue until less than 50000
      Select @rc=@@rowcount  --Commit the transaction
      Commit
     End
    这样用tablockx, holdlock两个锁吗?这两个锁什么作用?是不是整个表锁住不让别人再进行插入操作了?多谢!!