Replace Into - MySql Query
Aug 14th, 2009 by sherlock Hit :: 7288
Summary ::
- Try to insert the new row into TABLE
- While the insertion fails because a duplicate-key error (primary key)
- DELETE conflicting row that had duplicate key value from TABLE
- 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 become more efficient from ” DELETE FROM… INSERT INTO…”
but slower than UPDATE .
Use “INSERT … ON DUPLICATE KEY UPDATE…” if you’re looking a single unique column table (Primary Key).