Community Documentation

MySQLism: avoid using MySQL REPLACE syntax

Last updated August 28, 2009. Created by grub3 on August 28, 2009.
Log in to edit this page.

MySQL allows running INSERT or UPDATE in one single query, which is extremely useful.

REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted.

Unfortunately, this MySQL syntax is not supported by any other database. It should be avoided.

Try to use a combination of INSERTs and UPDATEs.

Reference: MySQL replace command.

Develop for Drupal

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here