Topic: Database update question

Just wanting to double check on this one. smile

In theory, is best to see if an entry matches certain criteria in a specific table before applying an UPDATE to change the value, or just do the UPDATE incase any rows match the criteria, without checking first?

I assume the second method, as there's one less query to the DB?

Screw the chavs and God save the Queen!

Re: Database update question

Depends really.  There are, potentially, situations where you would want to only update things that have changed and other cases where simply updating everything might be a better choice.  I don't think you can say that either method is THE method to use.

Dave

Re: Database update question

Well, the general consesus is usually 'let the database handle it', especially for constraints etc.
I'd go for the second case, you can always see if any rows were affected, so that isn't a reason to not do it this way either.

Ben
SVN repository for my extensions - The thread
Quickmarks 0.5
“Question: How does a large software project get to be one year late? Answer: One day at a time!” - Fred Brooks

Re: Database update question

Cheers chaps. smile It's only a straight forward update for a forum id if the topic reference id exists, so whether it exists isn't the important part, merely the changing of it if it does. Didn't want to be using the second method if had any known caveats though. big_smile

Thanks again. smile

Screw the chavs and God save the Queen!