1, Normal insertion :insert into

When inserting data , for example :

INSERT INTO books (name) VALUES (‘MySQL Manual’)

2, Ignore duplicate inserts :insert ignore into
When inserting data , If there is an error , Such as duplicate data , No errors will be returned , Return as warning only . So use ignore Make sure that the statement itself is OK , Otherwise it will be ignored . for example :

INSERT IGNORE INTO books (name) VALUES (‘MySQL Manual’)

3, Update if repeated :on duplicate key update

When primary perhaps unique When repeated , Then execute update sentence , as update After the useless statement , as id=id, It is the same 1 Same function , But mistakes are not ignored . for example , In order to achieve name Duplicate data insertion does not report errors , You can use the following statement :

INSERT INTO books (name) VALUES (‘MySQL Manual’) ON duplicate KEY UPDATE id =
id

4, Insert after judgment :insert … select … where not exist

according to select Whether to insert , Not only through primary and unique To judge , Other conditions can also be used . for example :

INSERT INTO books (name) SELECT ‘MySQL Manual’ FROM dual WHERE NOT EXISTS
(SELECT id FROM books WHERE id = 1)

5, Replace, delete and insert :replace into
If it exists primary or unique Same record , Delete it first . Insert new record .
REPLACE INTO books SELECT 1, ‘MySQL Manual’ FROM books
REPLACE INTO test(title,uid) VALUES (‘1234657’,’1001’);

Technology
©2019-2020 Toolsou All rights reserved,
Thoughts on multi tenant system Centos7 lower mysql8.0 To install and change the initial password ;vue use vue-clipboard2 Realize the function of copy link python in switch_to_alert Usage of vue Value transfer between parent-child and non parent-child components @Repository The role of annotations Note 14 : The second biggest obstacle to motivating others in R & D management exercises 11-5 Output string at specified position ( Essence )2020 year 6 month 26 day C# Class library Exception handling help class Python read Excel A column | Transfer deposit json