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
 Updating 50 million records from 5 billion

Author  Topic 

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 15:31:22
Hi Guys,

I am using a table with around 50 million records to update a table with 5 billion records. I have the appropriate indexes created on both these tables. I am doing the Updates in Batches of 1000 records. Is there a faster way to do this update? I cannot do Select INTO..

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 15:32:54
The fastest way to do it is by not looping. However, you will likely lock the table, causing problems for other connected users. You would also potentially have a disk space/tlog issue. So doing it in batches is recommended. It'll slow it down, however there'll be less impact. Plus if it needs to be rolled back, you only have to rollback that batch and not the entire thing.

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

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 15:38:33
Thanks Tkizer so if no one else need to log into the table and we have enough space for log file... doing in one go should save lot of time correct? Unless there are other isseus and it needs to be rolled back...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 15:41:20
That's correct, however you should test it to be sure.

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

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 15:46:34
Thank you tkizer.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 15:58:40
You're welcome, glad to help.

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

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 16:27:21
One more thing... doing the update in monthly batches (using a date field) or doing in same size batches using TOP () will have same effect rite? Thanks! Just wanted to check.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 16:32:42
What do you mean by "same effect"? The same end result? The same performance? ...?

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

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 16:40:37
Around same time to do the update? Right now I am only worried about time as log is fine and no one will use this table till tomm.. Thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-13 : 16:43:45
I can't comment on that, you'll need to test it.

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

Subscribe to my blog
Go to Top of Page

Ghanta
Yak Posting Veteran

96 Posts

Posted - 2011-06-13 : 16:44:45
You are rite. Thank you for your help.
Go to Top of Page
   

- Advertisement -