Skip to forum content
FluxBB.org Forums
Unfortunately no one can be told what FluxBB is - you have to see it for yourself.
You are not logged in. Please login or register.
Active topics Unanswered topics
FluxBB.org Forums » Programming » Database update question
Pages: 1
You must login or register to post a reply
Posts [ 4 ]
- From: South Yorkshire, England
- Registered: 2008-05-06
- Posts: 955
Topic: Database update question
Just wanting to double check on this one. 
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!
- From: Wake Forest, North Carolina
- Registered: 2008-05-10
- Posts: 45
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.
- From: Leuven, Belgium
- Registered: 2008-04-30
- Posts: 1,131
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
- From: South Yorkshire, England
- Registered: 2008-05-06
- Posts: 955
Re: Database update question
Cheers chaps.
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. 
Thanks again. 
Screw the chavs and God save the Queen!
Topic options
RSS topic feed
Pages: 1
You must login or register to post a reply
FluxBB.org Forums » Programming » Database update question