Home > Article > Backend Development > Use laravel to batch import excel, what to do if there is duplicate data
The project needs to import excel files in batches. What should I do if there are duplicate data? Do I need to query the database every time I insert data?
The project needs to import excel files in batches. What should I do if there are duplicate data in them? Do I need to query the database every time I insert data?
1. How to deal with duplicate data?
<code>可以先判断数据库是否有该数据。</code>
2. Do you need to query the database every time you insert data?
<code>是的。</code>
First remove duplicates to obtain data without duplication, and then insert into the database in batches. You can also try insert ignore into or replace into in MYSQL
If the query is slow, add a unique key to the field that cannot be repeated, and then use
INSERT IGNORE INTO