Batch Delete scripts for large tables

Source: Internet
Author: User

I did something silly yesterday. I built a new test database in the company and restored the formal database to the test database,
Change the recovery mode to simple, and then write a script to delete all business tables before this year. Then I went home.
Today, I ran to see that, er, the test database reached more than 200 GB. This makes you realize that the data volume of a single business table is large,
I used a single Delete statement to delete a single transaction, which caused the log to soar to more than 200 GB.
The batch deletion script provided by the big pineapple brother is as follows:

 While   1  =  1  Begin      Delete   Top ( 5000 ) From TB  Where Sysdate <=   '  2013-12-31  '      If   @ Rowcount   <   5000          Break  ;  Waitfor Delay '  00:00:05  ' 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.