Insert into a MySQL table or update if exists

前端 未结 11 2679
再見小時候
再見小時候 2020-11-21 04:27

I want to add a row to a database table, but if a row exists with the same unique key I want to update the row.

For example:



        
11条回答
  •  梦毁少年i
    2020-11-21 05:24

    When using SQLite:

    REPLACE into table (id, name, age) values(1, "A", 19)
    

    Provided that id is the primary key. Or else it just inserts another row. See INSERT (SQLite).

提交回复
热议问题