Home > Database > Mysql Tutorial > body text

What is the use of the MySQL IGNORE INSERT statement?

王林
Release: 2023-08-25 17:25:08
forward
1586 people have browsed it

MySQL IGNORE INSERT 语句有什么用?

Basically, the IGNORE INSERT statement is used to prevent duplicate data from being inserted into a MySQL table. If we use the INSERT IGNORE command instead of the INSERT command, then if a record is not a duplicate of an existing record, MySQL will insert it as usual, but if the record is a duplicate, the IGNORE keyword will tell MySQL to silently discard it without Generate an error. Its syntax is as follows -

Syntax

INSERT INGORE INTO table_name(…)
Copy after login

Here, table_name is the name of the table in which we want to insert the value.

Example

The following example will not cause errors and will not insert duplicate records.

mysql> INSERT IGNORE INTO person_tbl (last_name, first_name)
    -> VALUES( 'Jay', 'Thomas');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT IGNORE INTO person_tbl (last_name, first_name)
    -> VALUES( 'Jay', 'Thomas');
Query OK, 0 rows affected (0.00 sec)
Copy after login

The above is the detailed content of What is the use of the MySQL IGNORE INSERT statement?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!