Differences between insert ignore and INSERT

Source: Internet
Author: User

Example

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


Example

Insert into inserts data if any. If the primary key is not inserted

1. Multiple groups of values can be inserted in an insert statement at a time. Each group of values is enclosed by a pair of parentheses and separated by commas, as shown below:

Insert into 'News' (title, body, time) values ('www. bKjia. c0m', 'body 1', now (), ('title 2', 'body 2', now ());
 
 
The following code describes the differences between them:

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; // It is still 1, "bb", 13. Because id is the primary key, the primary key is repeated, but ignore is used, the error is ignored.
Replace into testtb (id, name, age) values (1, "aa", 12 );
Select * from testtb; // The data is changed to 1, "aa", 12

For more details, see http://www.bKjia. c0m/database/mysql/56643.htm

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.