合并语句在 MySQL 中可用吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42663074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is merge statement available in MySQL
提问by Gopal
I have to use INSERT
and UPDATE
in single query. For that SQL having MERGE
statement.
我必须在单个查询中使用INSERT
和UPDATE
。对于具有MERGE
语句的SQL 。
Is MERGE
statement supported in MySQL. If supported, please provide sample.
MERGE
MySQL是否支持语句。如果支持,请提供样品。
回答by Mehmood Memon
MERGE
is not supported by MySQL, However, there is other possible way of doing the same:
MERGE
MySQL 不支持,但是,还有其他可能的方法来做同样的事情:
INSERT...ON DUPLICATE KEY UPDATE
If you specify the ON DUPLICATE KEY UPDATE option in the INSERT statement and the new row causes a duplicate value in the UNIQUE or PRIMARY KEY index, MySQL performs an update to the old row based on the new values.
如果您在 INSERT 语句中指定 ON DUPLICATE KEY UPDATE 选项并且新行导致 UNIQUE 或 PRIMARY KEY 索引中的重复值,MySQL 将根据新值对旧行执行更新。