Replace Into - MySql Query
Jun 9th, 2008 by sherlock Hit :: 1092
Mechanism ::
- Try to insert the new row into the table
- While the insertion fails because a duplicate-key error occurs for a primary key or unique index:
- Delete from the table the conflicting row that has the duplicate key value
- Try again to insert the new row into the table
Syntac ::
REPLACE INTO F SELECT * FROM T;
REPLACE INTO F(a, b, c) SELECT a, b, c FROM T;
Summary:
REPLACE INTO becomes more efficient from DELETE FROM… INSERT INTO… but much slower performer than an UPDATE statement. Better use “INSERT … ON DUPLICATE KEY UPDATE…” as an alternative if you’re looking at a single unique column table (Primary Key).