Ignore duplicate data when inserting MYSQL Data

Source: Internet
Author: User

When inserting data in MYSQL, duplicate data is ignored. when inserting data in the program, existing data is not inserted, and non-existing data is inserted. You can use the stored procedure or not exists to determine whether the stored procedure EXISTS. When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".

1: Use replace into (This method uses the replacement method, which is a bit similar to deleting and then inserting) replace into Syntax REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT },...), (...),... Or: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name SET col_name = {expr | DEFAULT },... Or: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [(col_name,...)] SELECT... 2: Use INSERT [IGNORE] INTO (this method is highly efficient and can be used to determine whether it exists or not. Otherwise, it will be inserted) INSERT [IGNORE] INTO Syntax INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] {VALUES | VALUE} ({expr [...]

 


Related Article

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.