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

WBOY
Release: 2023-03-03 10:00:02
Original
2554 people have browsed it

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>
Copy after login

2. Do you need to query the database every time you insert data?

<code>是的。</code>
Copy after login

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

Related labels:
source:php.cn
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