insert ... on duplicate key update ...

https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html

用法

http://www.mysqltutorial.org/mysql-insert-or-update-on-duplicate-key-update/

When you insert a new row into a table if the row causes a duplicate in [UNIQUE](http://www.mysqltutorial.org/mysql-unique/) index or [PRIMARY KEY](http://www.mysqltutorial.org/mysql-primary-key/) , MySQL will issue an error.

However, if you specify the ON DUPLICATE KEY UPDATE option in the INSERT statement, MySQL will update the existing row with the new values instead.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。