zoukankan      html  css  js  c++  java
  • 分批删除大量数据

    -- specify the number of rows you want 
    --    to delete per 'gulp':
    DECLARE @count int
    SET @count = 2000
    
    -- keep track of the number of rows
    --    impacted by each gulp... once it
    --  drops below the intended number of rows
    --    then you're done... 
    DECLARE @rowcount int
    SET @rowcount = @count
    
    -- keep date same through entire operation
    DECLARE @cutoff datetime
    SET @cutoff = GETDATE() - 60 
    
    WHILE @count = @rowcount BEGIN
    
        -- archiving logic goes here... 
        -- (or it can take place BEFORE you 
        --    start with this 'nibbling operation')
        
        -- remember, nibbling deletes aren't the 
        --    only thing you can do, you can also do
        --    UPDATEs, INSERTs, MERGEs, etc. 
    
        DELETE FROM LorryLocations
        WHERE locationId IN (
            SELECT TOP (@count) locationId 
            FROM LorryLocations WITH(NOLOCK)
            WHERE
                [timestamp] < @cutoff
        )
        
        -- update the number of rows modified
        -- if it's less than @count, then this was
        -- our last pass... and the WHILE loop
        -- will break
        SET @rowcount = @@ROWCOUNT
                
        -- a few milliseconds is typically all you'll
        -- need for most operations, but toggle this
        -- value as needed
        WAITFOR DELAY '000:00:00.400'
    END
    
  • 相关阅读:
    JavaScript-----7.循环
    3. CSS新特性之动画
    JavaScript-----6.流程控制:分支
    JavaScript-----5.运算符
    JavaScript-----4.数据类型
    2. CSS新特性之2D转换transform
    JavaScript-----3.变量
    JavaScript-----2初识
    JavaScript---1.计算机的编程基础
    品优购学习心得
  • 原文地址:https://www.cnblogs.com/geass/p/2043950.html
Copyright © 2011-2022 走看看