基本上,ignore insert语句用于防止向mysql表中插入重复数据。如果我们使用 insert ignore 命令而不是 insert 命令,那么如果一条记录与现有记录不重复,mysql 会照常插入它,但如果该记录是重复的,那么 ignore 关键字会告诉 mysql 默默地丢弃它,而不生成一个错误。其语法如下 -
语法insert ingore into table_name(…)
这里,table_name是我们要在其中插入值的表的名称。
示例下面的示例不会出错出的同时,也不会插入重复的记录。
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)
以上就是mysql ignore insert 语句有什么用?的详细内容。