刪除一個表中的部分數據,數據量百萬級。
一般delete from 表
delete from 表名 where 條件;
此操作可能導致,刪除操作執行的時間長;日志文件急速增長;
針對此情況處理 delete top from
declare @onecount int set @onecount=1000000 print getdate() while 1=1 begin delete top(@onecount) from ysh where date<'2016-06-21' ; --此處不能寫任何語句 print也可能導致無法全部刪除@@rowcount影響行數 IF (@@rowcount<@onecount) BREAK; print getdate() end
說明 :@onecount 每次刪除的數據量,此處設置100w,可根據實際情況調整。
此操作刪除時間快,以及生成的日志量少。