Solved

We need to update every row in a busy production OLTP database table that contains approximately 50 million rows

Posted on 2011-02-24
3
465 Views
Last Modified: 2012-05-11
We need to update every row in a busy production OLTP database table that contains approximately 50 million rows. Any suggestionson how we may approach this?
0
Comment
Question by:tesla764
3 Comments
 
LVL 10

Accepted Solution

by:
John Claes earned 500 total points
ID: 34972004
I see 2 different approches. that are not to heavy upon a busy environment.


1 make a cursor and flow for every records over the update and make sure you commit
(Is not my proposal)


2)
Make a Stored procedure
let this run the folowing script until it returns 0 changed records


Update TABLE
Set Field='Value'
where TABLEID in (SELECT TOP 100 TABLEID from TABLE (nolock) where Field<>'Value')



the nolock option will make sure that the values are taken directly from the database and not from the TRansactionSet - this is a fast Query and we can fastly execute.
Execution will take some time, but no User will notice it


0
 
LVL 15

Expert Comment

by:Aaron Shilo
ID: 34972237
hi

option 1:

set rowcount 1000

update mytable
set value = @value.
where value <> @value

option 2:
do this in small controlled chunks.
use the PK to control the rows you retrive and update every batch and move forward.
0
 

Author Comment

by:tesla764
ID: 34974122
Thanks.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question