定期删除一个月前的数据,分批次删除
2013-04-11 16:40 Spring.Guo 阅读(536) 评论(0) 编辑 收藏 举报/*每天删除一个月以前的记录
*通过Job 每天凌晨2点执行
*/
DECLARE @num INT --一次删除记录数(可调整,建议不要超过4000)
DECLARE @CanDeleteRows INT -- 可以删的记录行数
SET @num =1000
SET @CanDeleteRows =0
SELECT @CanDeleteRows= COUNT(*) FROM prnbsn_CdbMarketPriceData
WHERE CdbUpdateDate<=dateadd(month,-1,getdate())
WHILE(@CanDeleteRows>0)
begin
DELETE TOP (@num) FROM prnbsn_CdbMarketPriceData WHERE CdbUpdateDate<=dateadd(month,-1,getdate())
SELECT @CanDeleteRows= COUNT(*) FROM prnbsn_CdbMarketPriceData WHERE CdbUpdateDate<=dateadd(month,-1,getdate())
PRINT @CanDeleteRows
END
GO