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

  • Home
  • SEARCH
  • 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 47521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:08:09+00:00 2026-05-10T16:08:09+00:00

A query that is used to loop through 17 millions records to remove duplicates

  • 0

A query that is used to loop through 17 millions records to remove duplicates has been running now for about 16 hours and I wanted to know if the query is stopped right now if it will finalize the delete statements or if it has been deleting while running this query? Indeed, if I do stop it, does it finalize the deletes or rolls back?

I have found that when I do a

 select count(*) from myTable 

That the rows that it returns (while doing this query) is about 5 less than what the starting row count was. Obviously the server resources are extremely poor, so does that mean that this process has taken 16 hours to find 5 duplicates (when there are actually thousands), and this could be running for days?

This query took 6 seconds on 2000 rows of test data, and it works great on that set of data, so I figured it would take 15 hours for the complete set.

Any ideas?

Below is the query:

--Declare the looping variable DECLARE @LoopVar char(10)       DECLARE      --Set private variables that will be used throughout       @long DECIMAL,       @lat DECIMAL,       @phoneNumber char(10),       @businessname varchar(64),       @winner char(10)      SET @LoopVar = (SELECT MIN(RecordID) FROM MyTable)      WHILE @LoopVar is not null     BEGIN        --initialize the private variables (essentially this is a .ctor)       SELECT          @long = null,         @lat = null,         @businessname = null,         @phoneNumber = null,         @winner = null        -- load data from the row declared when setting @LoopVar         SELECT         @long = longitude,         @lat = latitude,         @businessname = BusinessName,         @phoneNumber = Phone       FROM MyTable       WHERE RecordID = @LoopVar        --find the winning row with that data. The winning row means        SELECT top 1 @Winner = RecordID       FROM MyTable       WHERE @long = longitude         AND @lat = latitude         AND @businessname = BusinessName         AND @phoneNumber = Phone       ORDER BY         CASE WHEN webAddress is not null THEN 1 ELSE 2 END,         CASE WHEN caption1 is not null THEN 1 ELSE 2 END,         CASE WHEN caption2 is not null THEN 1 ELSE 2 END,         RecordID        --delete any losers.       DELETE FROM MyTable       WHERE @long = longitude         AND @lat = latitude         AND @businessname = BusinessName         AND @phoneNumber = Phone         AND @winner != RecordID        -- prep the next loop value to go ahead and perform the next duplicate query.       SET @LoopVar = (SELECT MIN(RecordID)      FROM MyTable     WHERE @LoopVar < RecordID)     END 
  • 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. 2026-05-10T16:08:09+00:00Added an answer on May 10, 2026 at 4:08 pm

    no, sql server will not roll back the deletes it has already performed if you stop query execution. oracle requires an explicit committal of action queries or the data gets rolled back, but not mssql.

    with sql server it will not roll back unless you are specifically running in the context of a transaction and you rollback that transaction, or the connection closes without the transaction having been committed. but i don’t see a transaction context in your above query.

    you could also try re-structuring your query to make the deletes a little more efficient, but essentially if the specs of your box are not up to snuff then you might be stuck waiting it out.

    going forward, you should create a unique index on the table to keep yourself from having to go through this again.

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

Sidebar

Ask A Question

Stats

  • Questions 71k
  • Answers 71k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer First of all, make sure you use a remove the… May 11, 2026 at 1:23 pm
  • added an answer The idea behind inheritance is that each class defines their… May 11, 2026 at 1:23 pm
  • added an answer Go into the Properties window for the project where you… May 11, 2026 at 1:23 pm

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.