Wednesday, July 22, 2009

INSERT ON DUPLICATE KEY UPDATE and REPLACE INTO

While reading and article came across one of powerful feature REPLACE INTO,I had used INSERT ON DUPLICATE KEY UPDATE but never used REPLACE INTO.

REPLACE works in a way that if the ID column(Primary Column) doesn't have the given value it will create a new entry in the table, however, IF the value exists already then it updates the existing entry in the table.

REPLACE INTO sessions VALUES ('$id', '$data', $ts).

Read about REPLACE INTO and Difference about INSERT ON DUPLICATE KEY UPDATE vs REPLACE INTO

No comments: