The original blog link

Blog.csdn.net/ThinkWon/ar…

Conclusion 1

1. If you want to catch a duplicate exception, use insert into

2. If a duplicate exception occurs and you want to save the old record and ignore the new record, use insert ignore into

Insert into… insert into… on duplicate key update

The record is inserted first, and if unsuccessful, the original record is deleted but the values of the fields after the UPDATE statement are retained, the retained values are merged with the values that need to be updated, and a new record is inserted. This operation causes the increment field to increment by 1

4. If duplicate exceptions occur and you want to delete old records and insert new records, use replace into

Reaplce into deletes the record with ID 1 before inserting the record

Conclusion 2

Replace into and Insert into on duplicate key update both try to insert records first. If the records fail, delete the records. Replace into does not retain the values of the original records. Insert into on duplicate key update is retained. Then insert a new record.