Import csv without duplicate records

1

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

    
asked by anonymous 12.04.2017 / 20:38

1 answer

0

Create the table you are going to 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, eg:

LOAD DATA INFILE 'file.csv' REPLACE INTO table[...]
    
14.11.2017 / 17:29