INSERT IGNORE
Insert rows while ignoring specific errors. This statement allows bulk inserts to continue even if some rows fail due to duplicate keys or data conversion issues.
Ignoring Errors
Examples
CREATE TABLE t1 (x INT UNIQUE);
INSERT INTO t1 VALUES(1),(2);
INSERT INTO t1 VALUES(2),(3);
ERROR 1062 (23000): Duplicate entry '2' for key 'x'
SELECT * FROM t1;
+------+
| x |
+------+
| 1 |
| 2 |
+------+
INSERT IGNORE INTO t1 VALUES(2),(3);
Query OK, 1 row affected, 1 warning (0.04 sec)
SHOW WARNINGS;
+---------+------+---------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------+
| Warning | 1062 | Duplicate entry '2' for key 'x' |
+---------+------+---------------------------------+
SELECT * FROM t1;
+------+
| x |
+------+
| 1 |
| 2 |
| 3 |
+------+See Also
Last updated
Was this helpful?

