REPLACE INTO
REPLACE INTO is a SQL statement in the DML Statements category. INSERT, but if a UNIQUE/PRIMARY KEY conflict exists, DELETES the old row and inserts a new one. MySQL-specific. The syntax is REPLACE INTO table_name (columns) VALUES (values);. It returns number of rows affected. A typical example: REPLACE INTO employees (id, name, email) VALUES (1, 'Bob', 'bob@test.com'); -- If id=1 exists, deletes and re-inserts A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows. More about this category: Data Manipulation Language — INSERT, UPDATE, DELETE, REPLACE, MERGE. Related DML Statements entries: INSERT INTO, UPDATE, DELETE, INSERT ... ON DUPLICATE KEY UPDATE, MERGE, INSERT INTO SELECT, UPSERT (PostgreSQL), DELETE with JOIN.