SQLite “INSERT OR REPLACE INTO” vs. “UPDATE … WHERE”

后端 未结 4 1929
暖寄归人
暖寄归人 2020-11-29 22:24

I\'ve never seen the syntax INSERT OR REPLACE INTO names (id, name) VALUES (1, \"John\") used in SQL before, and I was wondering why it\'s better than UPD

4条回答
  •  粉色の甜心
    2020-11-29 22:52

    I'm currently working on such a statement and figured out another fact to notice: INSERT OR REPLACE will replace any values not supplied in the statement. For instance if your table contains a column "lastname" which you didn't supply a value for, INSERT OR REPLACE will nullify the "lastname" if possible (constraints allow it) or fail.

提交回复
热议问题