REPLACE INTO tblNames (FirstName, LastName) VALUES ('John', 'Jones')
If there is a unique restriction of any type on FirstName , LastName or a combination thereof, and it is violated, the records are deleted and inserted with new values.
The record will be replaced if any of the conditions is met:
FirstName is UNIQUE , and the table has John ,LastName is UNIQUE and there are Jones in the table,FirstName, Lastname is UNIQUE , and the table has John Jones .
Note that the REPLACE operation is an INSERT , possibly following DELETE , which will always affect the table.
In newer versions of MySQL you should use INSERT … ON DUPLICATE KEY UPDATE .
Quassnoi
source share