Home  >  Article  >  Backend Development  >  Use laravel to batch import excel, what to do if there is duplicate data

Use laravel to batch import excel, what to do if there is duplicate data

WBOY
WBOYOriginal
2016-12-05 13:44:192548browse

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?

Reply content:

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

Statement:
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