gpt4 book ai didi

mysql - 截断插入与选择更新插入

转载 作者:行者123 更新时间:2023-11-29 05:09:55 26 4
gpt4 key购买 nike

我有一个用作临时表的表。一个 cron 每小时运行一次,为每一行设置一个特定的值。

| id | item_id | value |
+====+=========+=======+
| 1 | 5 | 52 |
| 2 | 34 | 314 |
| 3 | 27 | 189 |
| 4 | 19 | 200 |
+====+=========+=======+

我想知道的是先TRUNCATE 然后重新填充这个表是否更好,或者我宁愿SELECT 现有行,UPDATE 它或 INSERT 如果它不存在。

最佳答案

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.

关于mysql - 截断插入与选择更新插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41236936/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com