合并语句在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:14:55  来源:igfitidea点击:

Is merge statement available in MySQL

mysqlsql

提问by Gopal

I have to use INSERTand UPDATEin single query. For that SQL having MERGEstatement.

我必须在单个查询中使用INSERTUPDATE。对于具有MERGE语句的SQL 。

Is MERGEstatement supported in MySQL. If supported, please provide sample.

MERGEMySQL是否支持语句。如果支持,请提供样品。

回答by Mehmood Memon

MERGEis not supported by MySQL, However, there is other possible way of doing the same:

MERGEMySQL 不支持,但是,还有其他可能的方法来做同样的事情:

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 将根据新值对旧行执行更新。