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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:23:40+00:00 2026-06-13T11:23:40+00:00

I have a question on general database/sql server designing: There is a table with

  • 0

I have a question on general database/sql server designing:

There is a table with 3 million rows that is being accessed 24×7. I need to update all the records in the table. Can you give me some methods to do this so that the user impact is minimized while I update my table?

Thanks in advance.

  • 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-06-13T11:23:41+00:00Added an answer on June 13, 2026 at 11:23 am

    Normally you’d write a single update statement to update rows. But in your case you actually want to break it up.

    http://www.sqlfiddle.com/#!3/c9c75/6
    Is a working example of a common pattern. You don’t want a batch size of 2, maybe you want 100,000 or 25,000 – you’ll have to test on your system to determine the best balance between quick completion and low blocking.

    declare @min int, @max int
    
    select @min = min(user_id), @max = max(user_id)
    from users
    
    declare @tmp int
    set @tmp = @min
    
    declare @batchSize int
    set @batchSize = 2
    
    
    while @tmp <= @max
    begin
      print 'from ' + Cast(@tmp as varchar(10)) + ' to ' + cast(@tmp + @batchSize as varchar(10)) + ' starting (' + CONVERT(nvarchar(30), GETDATE(), 120) + ')'
      update users
      set name = name + '_foo'
      where user_id >= @tmp and user_id < @tmp + @batchsize and user_id <= @max
    
      set @tmp = @tmp + @batchSize
      print 'Done  (' + CONVERT(nvarchar(30), GETDATE(), 120) + ')'
    
      WAITFOR DELAY '000:00:001'
    
    end
    update users
    set name = name + '_foo' 
    where user_id > @max
    

    We use patterns like this to update a user table about 10x your table size. With 100,000 chunks it takes about an hour. Performance depends on your hardware of course.

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

Sidebar

Related Questions

My general question is, say you have a SQL Server 2005 database that's 20G
I have a general question about the way that database indexing works, particularly in
i have a general question about how sql server evaluates the joins.The query is
Pretty general question regarding triggers in SQL server 2005. In what situations are table
I am designing an SQL database (accessed via PHP/MySQL) and have questions about designing
Lets say I have a table in a sql server 2000 database called TransactionType:
I have a general question about interpreters of functional languages: Are there actually any
I have a general question that is rather open-ended (i.e. depends on platform, application
I have a general question about rails controllers/models: I have a model Providers, that
tl;dr general question about handling database data and design: Is it ever acceptable/are there

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.