Import csv without duplicating records

Asked

Viewed 598 times

1

I have a spreadsheet with 32000 records, and I need to play for a table in the database. The problem is that in this spreadsheet I don’t have the ID of the records and I can’t let it duplicate when I import.
I need to make sure that when I import it, it checks through the "store" field (which is the store’s name/social reason), if it already exists, it must update the record with the spreadsheet data, and if it does not exist, it will create a new record in the table.

  • You know SQL right?

  • 1

    Particularly, I would insert ALL records into a support table. After all this import completed to the database, I would only insert the single records into the final table, ignoring duplicate records. It assures me I don’t have to redo anything wrong.

  • I believe that the focus would be on performance, since there are several ways to do it. I would do the general insertion in the target table, and then select distinct or group by, and the records that add up to more than 1, delete.

  • This spreadsheet is excel?

1 answer

0

Create the table that you will import as the primary key in the "store" field. And in the import script add REPLACE. If it finds the same record it will update, example:

LOAD DATA INFILE 'file.csv' REPLACE INTO table[...]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.