Home >Database >Mysql Tutorial >MySQL: ON DUPLICATE KEY UPDATE 用法 避免重复插入数据_MySQL

MySQL: ON DUPLICATE KEY UPDATE 用法 避免重复插入数据_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:31:20993browse

bitsCN.com

INSERT INTO osc_visit_stats(stat_date,type,id,view_count) VALUES (?,?,?,?) ON DUPLICATEKEY UPDATE view_count=view_count+?INSERT INTO osc_space_visit_records(space,user,visit_count,ip,visit_time) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE visit_count=visit_count+1,ip=?,visit_time=NOW()

使用该语法可在插入记录的时候先判断记录是否存在,如果不存在则插入,否则更新,很方便,无需执行两条SQL

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn