Hi ZanyWeb. Here's a pop quiz for you, and the answer may surprise you.
The MySQL manual states the following about the REPLACE statement:
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.
Sounds pretty clear to me. If a row with the same primary key exists, it is deleted and then a new row is inserted.
So, given the above, if I execute the following statements in a client, what would you expect would happen behind the scenes in the storage engine?
CREATE TABLE t1 ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , padding VARCHAR(200) NOT NULL ); INSERT INTO t1 VALUES (1, "I love testing."); INSERT INTO t1 …[Read more]