Create if an entry doesn't exist, otherwise update?

后端 未结 4 1878
太阳男子
太阳男子 2021-01-30 14:07

Kinda strange to put it into words that short, heh.

Anyway, what I want is basically to update an entry in a table if it does exist, otherwise to create a new one fillin

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 14:27

    Use 'REPLACE INTO':

     REPLACE INTO table SET id = 42, foo = 'bar';
    

    See more in the MySQL documentation

提交回复
热议问题