Normally INSERT stops and rolls back when it encounters an error.
By using the IGNORE keyword all errors are converted to warnings, which will not stop inserts of additional rows.
The IGNORE and DELAYED options are ignored when you use ON DUPLICATE KEY UPDATE.
IGNORE
. You can get the old behaviour if you set OLD_MODE to NO_DUP_KEY_WARNINGS_WITH_IGNORE
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 | +------+ 2 rows in set (0.00 sec) 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 INSERT ON DUPLICATE KEY UPDATE for further examples using that syntax.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/insert-ignore/