Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update rows in production

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2009-02-17 : 14:00:39
hi,
can anyone how to update every row in a busy production OLTP database table that contains 50 million rows. Please describe how you might approach this, including your reasoning.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-17 : 14:02:43
quote:
Originally posted by sent_sara

hi,
can anyone how to update every row in a busy production OLTP database table that contains 50 million rows. Please describe how you might approach this, including your reasoning.





Looks like you are going to crash the server with your scary questions.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-02-17 : 14:04:15
I would do the update in batches via a WHILE loop (or similar). I would update probably 1000 rows in each batch. Make sure to commit each batch.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2009-02-17 : 14:04:16
Well first I have to ask you why you want to do this? I can't think of many cases where I would find the need for this. Leaving that aside though, your best bet would be to approach this in slices. Update some of the rows and then go back for another slice. This will keep your translog small and keep your lock time down. Also, do this during your period of least activity, one for your users sake and two so you have less wait time on a lock for your update. If you're in 2005 and your table is partitioned you could use the switch statement to move the data out, update it, move it back in.

Mike
"oh, that monkey is going to pay"
Go to Top of Page
   

- Advertisement -