MySQL - insert > update?

Started by Grudge, February 04, 2004, 02:54:22 PM

Previous topic - Next topic

Grudge

Hi,

OK. I'm gonna illustrate my question with example (albeit silly one). Say I have a table called topic_replies with the following columns:
ID_TOPIC
ID_MEMBER
replyCount

Basically, it holds the amount of replies someone has made to a topic. Now, say I want to have a function that recounts all the replies each member has made to every topic, and then updates the replyCount value with the correct one. One way to do this would be with a gizzilion UPDATE queries for all the new values. The second way I'm thinking would be to do a REPLACE INTO query. It could look like this:
REPLACE INTO topic_replies (ID_TOPIC, ID_MEMBER, replyCount) VALUES (3,4,2), (3,2,7)

etc etc.

Is the replace faster than all the updates - and how do I do it correctly - I mean the required table structure. Do I create index's on ID_TOPIC and ID_MEMBER or specify them in some way??

Hope this makes some sense!
I'm only a half geek really...

Advertisement: