GNU Info

Info Node: (mysql.info)REPLACE

(mysql.info)REPLACE


Next: LOAD DATA Prev: TRUNCATE Up: Data Manipulation
Enter node , (file) or (file)node

`REPLACE' Syntax
----------------

         REPLACE [LOW_PRIORITY | DELAYED]
             [INTO] tbl_name [(col_name,...)]
             VALUES (expression,...),(...),...
     or  REPLACE [LOW_PRIORITY | DELAYED]
             [INTO] tbl_name [(col_name,...)]
             SELECT ...
     or  REPLACE [LOW_PRIORITY | DELAYED]
             [INTO] tbl_name
             SET col_name=expression, col_name=expression,...

`REPLACE' works exactly like `INSERT', except that if an old record in
the table has the same value as a new record on a unique index, the old
record is deleted before the new record is inserted.  *Note `INSERT':
INSERT.

In other words, you can't access the values of the old row from a
`REPLACE' statement.  In some old MySQL version it looked like you
could do this, but that was a bug that has been corrected.

When one uses a `REPLACE' command, `mysql_affected_rows()' will return
2 if the new row replaced and old row.  This is because in this case
one row was inserted and then the duplicate was deleted.

The above makes it easy to check if `REPLACE' added or replaced a row.


automatically generated by info2www version 1.2.2.9