Insert insert several uses

1.insert ignore into 
when inserting data, such as when an error occurs, such as the duplicate data will not return an error, returns only as a warning. So be sure to use ignore the statement itself is no problem, otherwise it will be ignored. For example: 
the INSERT the IGNORE the INTO Books (name) the VALUES ( ' the MySQL Manual ' )


 2.on Key Duplicate update 
when the primary unique or repeated, the update statement is executed, as described later update is unnecessary statements, such as ID = ID, the same function 1 the same, but the error will not be ignored. For example, to achieve repeatable name data insertion is not being given, may be used at statement:
 the INSERT  the INTO Books (name) the VALUES ( ' the MySQL Manual ' ) the ON Duplicate KEY  the UPDATE ID = ID


 3.Insert ... Not exist SELECT ... WHERE
The conditions for determining whether the select inserted, can only be determined by the primary and UNIQUE, but also through other conditions. For example: 
the INSERT  the INTO Books (name) the SELECT  ' the MySQL Manual '  the FROM Dual the WHERE  the NOT  EXISTS ( the SELECT ID the FROM Books the WHERE ID =  . 1 )


 4.replace INTO 
If the primary presence or identical records unique, is first removed. Then insert a new record. Note that if the original record exists (a1, b1, c1), the new record as (a1, b2), then replace the c field is null
 the REPLACE  the INTO Books the SELECT  . 1 , ' the MySQL Manual '  the FROM Books

 

Guess you like

Origin www.cnblogs.com/nvsky/p/11084264.html