Home >Database >Mysql Tutorial >MySQL中实用sql语句

MySQL中实用sql语句

WBOY
WBOYOriginal
2016-06-07 16:38:46956browse

1、如果数据库存在则更新 如果不存在则插入这个插入的数据中必须含有唯一索引字段 insert? into? . on duplicate key update eg. ?insert?into?t_test?set?ikey=1,value=a',value2=1?on?duplicate?key?update?value2=value2+1; 2、插入数据库 存在的话先删除

1、如果数据库存在则更新 如果不存在则插入 insert? into? …. on duplicate key update eg. ?insert?into?t_test?set?ikey=1,value=’a',value2=1?on?duplicate?key?update?value2=value2+1; 2、插入数据库 存在的话先删除后插入 不存在直接插入 eg. replace?into?t_test?set?ikey=1,value=’a',icount=0 则表中有ikey为1时,先删除旧数据.然后插入新数据.否则直接插入数据
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