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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 What's faster - Transaction?

Author  Topic 

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2011-01-26 : 17:05:46
I have a loop that will run lets say 1,000,000 times. Inside the loop there is some calculation then an update and an insert. What would work fastest - the entire process in one transaction? To commit the transaction at every x loops? Or to commit the transaction at every iteration? Or shouldn't make any difference?

Lets say no one else is using these tables during the processing.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-26 : 17:06:41
Commit it each time because your rollback is going to gigantic if any part fails. Plus you're going to bloat the tlog if you have one large transaction.

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

Subscribe to my blog
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-01-26 : 17:20:28
Is the loop required? No set based logic can be applied?



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page
   

- Advertisement -