I am writing a program that accesses a database in order to make sure values are up to date. For example(this isn’t my real issue), I have an object that has a unique property. I want to ensure that the database has that same unique value saved. If it doesn’t, I want to update the database. This would happen in a script that runs in the background repeatedly to ensure that the value’s stay synchronized.
So my question is, would it be more cost effective to SELECT the value and compare, then UPDATE. Or should I just UPDATE automatically?
I imagine the SELECT and compare might be more efficient then just updating all the time, but I don’t know for certain.
Which should I go with?
Thanks (I apologize if this is a dumb question).
It is a good question. It needs a sound knowledge of SELECT and UPDATE queries.
UPDATE is used when you need to update existing records in a table with WHERE as to specify which record you need to update. so better to use UPDATE query.
As far as cost and time effective, you can use different query analyzer to analysis the queries.