首页 > 代码库 > Sql语句摘要

Sql语句摘要

1.分批更新数据库

declare @x int
set @x=1
while(@x<=51)
begin
begin tran
update UserFavorite set UserFavorite.firstpublishtime = product.lastpublishtime
from UserFavorite,product where UserFavorite.productid = product.id
and UserFavorite.id between (@x-1)* 10000 and @x*10000
commit tran
set @x=@x+1
WAITFOR DELAY ‘00:00:30‘; --等待5秒
end

Sql语句摘要