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

后端 未结 4 1959
太阳男子
太阳男子 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:15

    As the others have said, REPLACE is the way to go. Just be careful using it though, since it actually does a DELETE and INSERT on the table. This is fine most of the time, but if you have foreign keys with constraints like ON DELETE CASCADE, it can cause some big problems.

提交回复
热议问题