REPLACE

Syntax:

REPLACE [LOW PRIORITY | DELAYED]
  [INTO] table_name
  SET column_name1=expression1, column_name2=expression2,...

or

REPLACE [LOW PRIORITY | DELAYED]
  [INTO] table_name [(column_name,...)]
  VALUES (expression,...),(...)...

or

REPLACE [LOW PRIORITY | DELAYED]
  [INTO] table_name [(column_name,...)]
  SELECT...

Description: Adds new rows of data to an existing table given by table_name. Works like INSERT, but where it tries to insert a row with the same primary or unique key as an existing row, the old row is replaced by the new.

REPLACE can take a number of forms as shown previously. In the first form using SET, each column is named together with the value to which it is to be set.

The second form takes the VALUES keyword with a list ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.