Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1040563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:14:23+00:00 2026-05-16T15:14:23+00:00

i have to delete a large amount of data. truncate is not possible because

  • 0

i have to delete a large amount of data. truncate is not possible because of relations.
And I don’t wanna drop the table because of views.
I am using code below but is there better idea?

delete from table
WHILE 1=1
BEGIN
BEGIN TRAN
DELETE  top (1000000) from table
IF @@rowcount < 1000000 BREAK
WAITFOR DELAY '00:00:00:010'
COMMIT
end  
DELETE  from table
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:14:24+00:00Added an answer on May 16, 2026 at 3:14 pm

    Truncate table would be the best by far.

    If you’re worried about relationships because of the referencial integrity, than I suggest you update separately those tables that reference it by foreign key (e.g. if foreign keys have ON DELETE SET NULL then UPDATE RefTbl SET Key = NULL WHERE Key IS NOT NULL, similarly, delete if cascade etc…).

    Alternatively, if you don’t want that, you can alter your query to be a bit quicker by using ROWCOUNT:

    --other code for loop
    SET ROWCOUNT 1000000 --this limits the number of rows that will be processed
    DELETE FROM Table1
    

    Also, I’m not sure why are you doing this inside a transaction? It would create a huge transaction log and impact your performance severely… When you’re performing stuff like dumping table content usually transactions are not relevant (it could be relevant in your case, but I’m just saying it’s rarely the case). If you do need transaction, than at least move your delay out of it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to delete some rows from a data table. I've heard that it
I have a large file and need to delete last 512 bytes. I don't
I want to have a delete user link in a normal Activerecord table, but
I want to distribute a large amount of data to different C# applications. For
I have an application that stores large amount of files (XML and binary) in
I have a large data file, which is zipped, and approximately 20MB. When it's
I have a memory leak issue in my application which loads a large amount
Like many of you, I have to deal with a large amount of files:
I have a batch process that imports large amounts of data. I am doing
I have a really large excel file and i need to delete about 20,000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.