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 =

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 :

(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’);

©2019-2020 Toolsou All rights reserved,
html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail java Four functional interfaces ( a key , simple )os Simple use of module Some East 14 Pay change 16 salary , Sincerity or routine ?