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
    
  • 相关阅读:
    iOS
    iOS
    iOS
    iOS
    iOS
    使用jquery获取radio的值
    CSS margin属性与用法教程
    CSS框架960Grid从入门到精通一步登天
    从程序员到项目经理
    华为离职副总裁徐家骏:年薪千万的工作感悟
  • 原文地址:https://www.cnblogs.com/geass/p/2043950.html
Copyright © 2011-2022 走看看