Is it possible to insert a row but only if a value does not already exist?

前端 未结 7 1840
谎友^
谎友^ 2021-02-04 05:26

Is it possible to insert a row, but only if one of the values already in the table does not exist?

I\'m creating a Tell A Friend with referral points for an eco

7条回答
  •  孤独总比滥情好
    2021-02-04 05:58

    MySQL offers REPLACE INTO http://dev.mysql.com/doc/refman/5.0/en/replace.html:

    REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.

提交回复
热议问题