Avoiding inserting duplicate rows in mySQL

后端 未结 4 2089
刺人心
刺人心 2020-12-09 22:22

I have a table with an auto_inc id (primary key). I am trying to avoid the insertion of duplicate rows.

Example of a duplicate row:

id           


        
4条回答
  •  失恋的感觉
    2020-12-09 23:19

    You should use ON DUPLICATE KEY UPDATE and declaring the fields as unique .

    If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row is performed.

提交回复
热议问题