In SQL Server, a large data table has the condition to delete the data.

Source: Internet
Author: User

In SQL Server, You need to delete some data in a large data table Table1 (more than 10 million records). If you use the delete method, the execution usually times out. You can use the following method:

Select the record you want to keep to the new table.

Select * into Table2 From Table1 Where Time> = '2017-03-10'


Then directly Truncate Table1. No log is recorded in whatever recovery mode: Truncate table Table1

Finally, rename Table2 to Table1: EC sp_rename 'table2' and 'table1'

Note:

The select * into statement does not have this function, but simply generates tables, excluding primary keys and default values. To be the same as the source Table, you can generate the Create Table script for the source Table, modify the Table name, key name, and constraint name, and Create table2 first ,, USE insert into table2 select * from table1 to copy the data.

Related Article

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.