【发布时间】:2013-09-23 02:02:40
【问题描述】:
我有一个带有 3 列 A、B、C 和 A 和 B 的唯一表的 SomeTable
如果 A、B 已经存在,我会从客户端传递一些值以插入或更新 C。 我想知道服务器是否为每个值完成了更新或插入,如果是更新我想要 C 的旧值....
我目前正在这样做
While values to insert {
Insert A,B,C
if success memorizing the value continue the while
else if the sql error is "duplicate key" {
select old value of C for A,B
update C for A,B...
}
}
这意味着对 MySQL 的 3 次调用......
有没有办法通过触发器、过程或“魔术”查询来做到这一点?
【问题讨论】:
-
你想on duplicate key update还是
REPLACE?
标签: php mysql insert-update