tags:

views:

35

answers:

1

This is more of a theory question.

If I'm running 50,000 queries that insert new rows, and 50,000 queries that updates those rows, which one will take less time?

+2  A: 

Insert would be faster because with update you need to first search for the record that you are going to update and then perform the update.

Though this hardly seems like a valid comparison as you never have a choice whether to insert or update as the two fill two completely different needs.

EDIT: I should add too that this is with the assumption that there are no insert triggers or other situations that could cause potential bottlenecks.

spinon
not entirely true... you could have a table listing 'last login' times. You could either update the records or insert new ones every time a user logs in. Though such a behaviour would also depend on access times, table growth rates, etc.
Jonathan Fingland
Not necessarily - Update could be faster due to fewer page splits depending on what the clustered and other indexes are and a myriad of other factors.
Martin Smith
I agree that there are factors that could contribute to this being not the case. But I think in most scenarios of everyday users this is not. But I could be wrong.
spinon