Sqlserver: 循环删除表数据

Sqlserver: 循环删除表数据,第1张

概述USE mydatabaseGO/******************************************************** Data_ItemList_Additional is Data_ItemList'Additional* Data_ItemList_Additional store bigdata for another table**
USE mydatabaseGO/******************************************************** Data_ItemList_Additional is Data_ItemList'Additional* Data_ItemList_Additional store bigdata for another table** delete userID'info from table Data_ItemList_Additional* Database: mydatabase* author: greatwqs* createtime: 2012-08-15*********************************************************/DECLARE @icount INTEGER    SELECT @icount = COUNT(1)FROM [dbo].[Data_ItemList] WITH(NolOCK)WHERE [userID] = 2SELECT @ICOUNT     WHILE @icount > 0 BEGIN    DELETE top (2000)    FROM [dbo].[Data_ItemList_Additional]   AS a    INNER JOIN (        SELECT top 20000 ItemID        FROM [dbo].[Data_ItemList] WITH(NolOCK)        WHERE [userID] = 2    )AS b    ON a.ItemID = b.ItemID        SET @icount = @icount -20000    WAITFOR DELAY '00:00:05'END

 

删除Data_ItemList_Additional表中数据,隔5秒钟删除2万条数据,sqlserver不至于负载过大.

总结

以上是内存溢出为你收集整理的Sqlserver: 循环删除表数据全部内容,希望文章能够帮你解决Sqlserver: 循环删除表数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1177746.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存