Reputation: 9123
I have a table that I am using as a temporary table. A cron runs every hour to set a certain value for each row.
| id | item_id | value |
+====+=========+=======+
| 1 | 5 | 52 |
| 2 | 34 | 314 |
| 3 | 27 | 189 |
| 4 | 19 | 200 |
+====+=========+=======+
What I would like to know is if it is better to first TRUNCATE
and then refill this table or that I could rather SELECT
the existing row, UPDATE
it or INSERT
it if it doesn't exist.
Upvotes: 1
Views: 466
Reputation: 79
Insert the record if it doesn't exist in your temporary table and if it has already in your temporary table but you need to update it's value then update the specific record by only target it. It would be more wise, because it will be reduce the operation execution time.
Upvotes: 3