Implement duplicate key values for MySQL insertion and processing, IGNORE

Source: Internet
Author: User

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:

 
 
  1. MySQL> insert ignore into test1(id,name,type)(select id,name,type from test2);   
  2. Query OK, 3 rows affected (0.01 sec)   
  3. Records: 4 Duplicates: 1 Warnings: 0   
  4. MySQL> select * from test1;   
  5. +-----+------+------+   
  6. | id | name | type |   
  7. +-----+------+------+   
  8. | 101 | aaa | 1 |   
  9. | 102 | bbb | 2 |   
  10. | 103 | ccc | 3 |   
  11. | 203 | ccc | 3 |   
  12. | 202 | bbb | 2 |   
  13. | 201 | aaa | 1 |   
  14. +-----+------+------+   
  15. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.