Name

REPLACE

Synopsis

REPLACE [LOW_PRIORITY|DELAYED] [INTO] table [(column,...)]

    VALUES ({expression|DEFAULT},...)[, (...)]

REPLACE [LOW_PRIORITY|DELAYED] [INTO] table

    SET column={expression|DEFAULT},  . . . 

REPLACE [LOW_PRIORITY|DELAYED] [INTO] table [(column,...)]

    SELECT...

Use this statement to insert new rows of data and to replace existing rows where the PRIMARYKEY or UNIQUE index key is the same as the new record being inserted. The LOW_PRIORITY flag instructs the server to wait until there are no queries on the table named, including reads, and then to lock the table for exclusive use by the thread so that data may be inserted and replaced. When the statement is finished, the lock is released automatically. For busy servers, a client may be waiting for quite a while. The DELAYED flag will free the client by storing the statement in a buffer for processing when the table is not busy. The client won’t be given notice of the success of the statement, just that it’s buffered. If the server crashes before the changes to the data are processed, the client will not be informed and the buffer contents will be lost. The INTO keyword is optional, and is a matter of style preference and compatibility. This statement requires INSERT and DELETE privileges, because it is potentially a combination of both.

Three basic statement structures may be used to insert and replace data. For the syntax of the first one shown, the values for each row are placed in parentheses after the VALUES keyword. ...

Get MySQL in a Nutshell 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.