The difference between insert IGNORE and insert INTO

Source: Internet
Author: User

Cases

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


Insert ignore into table (name) select name from Table2


Cases

Insert into there is no data inserted, if the primary key is not inserted

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

INSERT INTO ' news ' (Title,body,time) 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);
The SELECT * from testtb;//is still 1, "BB", 13, because the ID is the primary key, the primary key is duplicated but the error is ignored when the ignore is used
Replace into TESTTB (id,name,age) VALUES (1, "AA", 12);
SELECT * from TESTTB; Data into 1, "AA", 12

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.