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: 循环删除表数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)