The difference between insert IGNORE and insert INTO

Source: Internet
Author: User

Cases

Insert Ignore indicates that if the same record already exists, the current new data is ignored;


Insert ignore into table (name) select name from Table2


Cases

INSERT into has no data inserted, if the primary key is not inserted

A 1.insert statement can insert multiple sets of values at a time, each set of values enclosed by a pair of parentheses, separated by commas, as follows:

INSERT INTO ' News ' values (' www.111cn.net ', ' body 1 ', now ()), (' Title 2 ', ' body 2 ', now ());


The following are the differences between code descriptions, as follows:

CREATE TABLE TESTTB (
ID int NOT NULL PRIMARY key,
Name varchar (50),
Age int
);

Insert into TESTTB (id,name,age) VALUES (1, "www.111Cn.net", 13);
SELECT * from TESTTB;
Insert Ignore into TESTTB (Id,name,age) VALUES (1, "AA", 13);
SELECT * from testtb;//is still 1, "BB", 13, because ID is primary key, duplicate primary key but use ignore error is ignored
Replace into TESTTB (id,name,age) VALUES (1, "AA", 12);
SELECT * from TESTTB; Data becomes 1, "AA", 12

For more detailed information, please see: http://www.111cn.net/database/mysql/56643.htm

The difference between insert IGNORE and insert INTO

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.