Home  >  Article  >  Database  >  What is the use of the MySQL IGNORE INSERT statement?

What is the use of the MySQL IGNORE INSERT statement?

王林
王林forward
2023-08-25 17:25:081459browse

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(…)

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete