In the previous article, we mentioned two ways to INSERT and process duplicate key values in MySQL: replace into and insert into on duplicate key update, today, we will introduce the ignore into method for implementing MySQL insertion and processing duplicate key values.
IGNORE
Determine whether or not there is, there is no insert, otherwise insert. It is easy to understand that when inserting, MySQL will not try to execute this statement because it violates the uniqueness constraint. For example:
- MySQL> insert ignore into test1(id,name,type)(select id,name,type from test2);
- Query OK, 3 rows affected (0.01 sec)
- Records: 4 Duplicates: 1 Warnings: 0
- MySQL> select * from test1;
- +-----+------+------+
- | id | name | type |
- +-----+------+------+
- | 101 | aaa | 1 |
- | 102 | bbb | 2 |
- | 103 | ccc | 3 |
- | 203 | ccc | 3 |
- | 202 | bbb | 2 |
- | 201 | aaa | 1 |
- +-----+------+------+
- 6 rows in set (0.00 sec)
The above content is an introduction to the ignore into method used to insert and process duplicate key values in MySQL. I hope you will find some gains.
The above content describes the ignore into method used to insert and process duplicate key values in MySQL. I hope it will help you in this regard.