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 243261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:54:23+00:00 2026-05-11T20:54:23+00:00

I have a pretty large table: 20+ million rows and I need to update

  • 0

I have a pretty large table: 20+ million rows and I need to update about 5% of that – or 1 million rows.

Unfortunately, I am updating the (int) column that is being used as the clustered index.

My question is:
What is the fastest way to update these rows?

I have tried updating the rows directly:

update t1
set t1.groupId = t2.groupId
from
    table t1
join newtable t2 on t1.email = t2.email

but this takes WAY too long (I stopped it after 3 hours)

I assume that this is because the entire row (which has 2 datetimes, 2 varchars, and 2 ints) is being moved around for each update.

What if I dropped the clustered index first, then did the updates, then recreated the clustered index? Would that be faster?

Note: I have a nonclustered index on email, in case anyone thinks it’s the select part of the query that is slow. It’s not.

  • 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-11T20:54:23+00:00Added an answer on May 11, 2026 at 8:54 pm

    Here’s what I did (and it was much faster):

    1. I dropped the clustered index.
    2. I ALSO dropped foreign keys
      references (the two other int
      columns).
    3. I ran the update statement
    4. I recreated the index, which was faster than expected. (This is the original reason I asked SO first).

    This brought the entire process down to a matter of seconds. Yes, ~ 1 million rows in about 15 seconds.

    The second step was crucial because the foreign keys were forcing the update to do some sort of spool on the related tables, which each also have a large number of rows.

    The number of physical reads were tripled because of these foreign key lookups.

    I’m not sure why SQL Server needs to do that, but my guess is that it still performs the integrity check even if I’m not updating that column but I am moving the entire row (clustered column update).


    As a side note, I had also tried running the update in batches:

    update top(1000) t1
    set t1.groupId = t2.groupId
    from
        table t1
    join newtable t2 on t1.email = t2.email
    

    This was fine (and seemed to scale up to about 10K per batch) but it still was on the order of 1-2 minutes each batch.


    In summary, I’ve learned that for bulk updates, temporarily removing indexes can be very helpful.

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

Sidebar

Related Questions

I have a pretty large table (20M records) which has a 3 column index
I have a very large table with a fulltext indexed column. If I partition
I have a relatively large csv/text data file (33mb) that I need to do
I have a pretty large db in MySql, and I need to take backups
I've been creating this pretty large web application for sometime and have been updating
I'm looking at building a Rails application which will have some pretty large tables
I have a bunch of pretty large CSV (comma separated values) files and I
I have pretty big background of .net, and I've decided that i want to
I have a pretty standard table set-up in a current application using the .NET
I have a pretty complicated Linq query that I can't seem to get into

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.