“
If you use the IGNORE keyword, errors that occur while executing the INSERT statement are ignored. For example, without IGNORE, a row that duplicates an existing UNIQUE index or PRIMARY KEY value in the table causes a duplicate-key error and the statement is aborted. With IGNORE, the row is discarded and no error occurs. Ignored errors may generate warnings instead, although duplicate-key errors do not.
”
Mysql官方文档中提供标准的语法:
复制代码 代码如下:
INSERT IGNORE
INTO tbl_name
[PARTITION (partition_name,...)]
[(col_name,...)]
{VALUES | VALUE} ({expr | DEFAULT},...),(...),...
或者
复制代码 代码如下:
INSERT IGNORE
[INTO] tbl_name
[PARTITION (partition_name,...)]
[(col_name,...)]
SELECT ...
可见除了多了个IGNORE关键字以外,跟一般INSERT语句并无区别。
举个栗子:
1.建一张测试用的表
复制代码 代码如下: