The Replace
performs two actions, it first performs deletion after insertion, this can cause some problems like:
- If you have a foreign key constraint pointing to this line -
Replace
will fail.
- If your foreign key is set to cascade delete,
Replace
will cause rows from other tables to be deleted
- Uninformed fields will have information lost, just because it deletes the row if it exists and inserts another one at the end of the table with just the fields and data passed in the query.
Already using INSERT
... ON DUPLICATE KEY UPDATE
this problem does not occur, therefore it is recommended that you choose it.