This blog is my memo for collecting IT stuffs. And some my free softwares.Please use facebook to leave comments.

difference b/w REPLACE INTO and INSERT ON DUPLICATE KEY UPDATE

Last update 2009-06-27 05:22:44 (More than 1 year old)

The purpose for using those 2 syntacs is the same, "update a record if the record exist, otherwise insert a record."
But they work slightly in different way.

REPLACE INTO will replace record as it reads. When the PK is used to search record, the record will be simple updated.
But if other unique keys than PK is used, the record will be deleted and insert a new record. It means it will generate new auto number if the key is set to auto_increment.

On the other hand, INSERT ON DUPLICATE KEY UPDATE will simply update all the time.

Both are very useful unless you use them in wrong way.

Last update 2009-06-27 05:22:44

Comment Delicious

todo
facebook support
Page transaction
RSS feed
Search
Auth
Last update
Category
Multi-language
User
Open source
Environment
php-5.1.6 with PDO
SQLite-3.3
IE6
FireFox-1.5
RSS
Unauthorized

Search
Google