The REPLACE statement works just like INSERT, except that if a row already exists in the table with the same PRIMARY KEY value as the new data, the new row replaces it. Therefore, REPLACE never causes a PRIMARY KEY violation.
The syntax for REPLACE is just like INSERT, or you can use the alternative syntax with SET, if you prefer. The following examples both perform the same operation: to replace the MINI product with a new description, weight, and price.
mysql> REPLACE INTO products -> (product_code, name, weight, price) -> VALUES ('MINI', 'Mini produt', '1.25', 3.99); Query OK, 2 rows affected (0.00 sec)
mysql> REPLACE INTO products -> SET product_code = 'MINI', -> name = 'Mini product', -> weight = 1.25, -> price = ...