viralpatel.info
News: www.viralpatel.info >> blog <new> !
Blog


Twitt this! Email this!

REPLACE INTO and INSERT INTO ... ON DUPLICATE KEY UPDATE


----------------------------------
- Similarity:
-* Both INSERT a row into a database table if PRIMARY KEY or UNIQUE field specified in the SQL, is not present in table.
- Difference:
- If PRIMARY KEY or UNIQUE field specified in the SQL, is already present in table,
-* REPLACE INTO
-** DELETEs the row from the table and then INSERTs a new row with data specified in REPLACE SQL.
-** primary key / uniqe field value is updated.
-** 2 SQL operations are performed.
-** For REPLACE SQL, you need DELETE and INSERT privileges.
-** Data values not present in REPLACE SQL will be set to their default values & older values of the row ( if any ) will be lost.

-* INSERT INTO ... ON DUPLICATE KEY UPDATE
-** UPDATEs the row with data specified in INSERT INTO ... ON DUPLICATE KEY UPDATE SQL.
-** primary key / uniqe field value is updated.
-** Only 1 SQL operation is performed.

source : Impacts of REPLACE INTO