You are not logged in.
- Topics: Active | Unanswered
Pages: 1
#1 2009-06-29 10:07:29
- MattF
- Member

- From: South Yorkshire, England
- Registered: 2008-05-06
- Posts: 1,230
- Website
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!
Offline
#2 2009-06-29 11:47:36
- Dave
- Member
- 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.
Dave
Offline
#3 2009-06-29 11:58:19
- elbekko
- Former Developer

- From: Leuven, Belgium
- Registered: 2008-04-30
- Posts: 1,131
- Website
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
Offline
#4 2009-06-29 15:06:45
- MattF
- Member

- From: South Yorkshire, England
- Registered: 2008-05-06
- Posts: 1,230
- Website
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!
Offline
Pages: 1
