Bulk inserts or updates the usage of ON DUPLICATE KEY UPDATE

The actual development process, you may encounter this demand, first determine whether there is a record, if not, add a record, if present, to modify the data. Specify ON DUPLICATE KEY UPDATE INSERT statement at the end of these problems can be solved.

Its usage is as follows: If you specify ON DUPLICATE KEY UPDATE INSERT statement at the end, and inserted line can cause a duplicate value UNIQUE index or PRIMARY KEY, then in the event of an UPDATE operation is repeated row value, if not the only cause duplication value, INSERT operation is performed.

The following sql: database tables need to establish a unique index 

UNIQUE KEY `uniq_relation_id_field_name` (`relation_id`,`field_name`,`relation_type`) USING BTREE

 

Guess you like

Origin www.cnblogs.com/kobe-lin/p/11680334.html