In MySQL, we can use the REPLACE
statement to insert data if we think that some rows need to replace existing rows.
The REPLACE
statement works just like the INSERT
statement, except that if it contains rows with the same PRIMARY KEY
or UNIQUE
index as those in the table, then it replaces those rows in the table. It does this by deleting the old row and then inserting the new row.
To use the REPLACE
statement, we must have both the INSERT
and DELETE
privileges for the table.