开发者

Will Delete SQL locks the table which prevents new data insert into SQL Server 2005?

If I try to delete a brunch of data 开发者_开发知识库from a table. say

DELETE FROM myTable Where CreationDate < GetDate()

that takes hours to be deleted, will this table be locked and no new insert can happened?

This table doesn't self reference itself. I would assume I can still insert new data while it is deleting. Will the delete sql uses an exclusive lock that prevents all access to the table?

Thanks


You can batch them to prevent it from locking the whole table:

WHILE 1 = 1
  BEGIN
        DELETE  TOP 10000 FROM  myTable WHERE CreationDate < GetDate()

        IF @@ROWCOUNT = 0
            BREAK
  END


There are a lot of things that could change this behavior. However, if by a lot you mean over 5K records than it will probably lock. You can avoid this by using smaller batches or specifying an isolation level that will not lock.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜