多谢,今天在网上看到一篇文章说为了提高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两个锁吗?这两个锁什么作用?是不是整个表锁住不让别人再进行插入操作了?多谢!!
--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两个锁吗?这两个锁什么作用?是不是整个表锁住不让别人再进行插入操作了?多谢!!