SQL Server百萬級大數據量刪除


刪除一個表中的部分數據,數據量百萬級。

一般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,可根據實際情況調整。

此操作刪除時間快,以及生成的日志量少。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM