Batch Delete large amounts of data

Source: Internet
Author: User
-- Specify the number of rows you want -- to delete per 'gulp': declare @ count intset @ 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 intset @ rowcount = @ count -- keep date same through entire operationdeclare @ cutoff datetimeset @ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.