开发者社区 问答 正文

MySQL高效update已存在数据,insert新数据,如何做?

现在需要网表中插入若干个标签
表结构
id int auto_increment not null primary key,
tagname varchar(50) not null,
postcount int not null default 0
但这批需要插入或更新的标签有的已经在表中了,这时需要将postcount增1
如果标签不存在,则插入,并且返回这两种tag的id

展开
收起
落地花开啦 2016-02-13 11:27:19 2449 分享 版权
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    将 tagname 作为唯一健,然后使用 merge sql,类似 insert into …… on duplicatkey update ...

    2019-07-17 18:41:52
    赞同 展开评论