-1

Preventing duplicate row insertion in mysql while importing csv file.I want to insert data into mysql table via importing csv file. how to prevent duplicate row insert?

Nullify
  • 17,505
  • 7
  • 33
  • 58
only chande
  • 99
  • 2
  • 10

1 Answers1

2

Create an UNIQUE index in the column which might have dups, then

LOAD DATA INFILE 'file.csv' IGNORE INTO TABLE table_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
ESCAPED BY '"' LINES TERMINATED BY '\n';
HashSu
  • 1,404
  • 1
  • 10
  • 13
  • i dont have good knowledge in php mysql sir, if u dont mind can u explain clearly please. thank u. – only chande Jul 22 '15 at 14:35
  • the column which you think has duplicates create an unique key index on that. go to mysql terminal alter the table which you have command would be " alter table table name add unique index `index name` `column name`; https://dev.mysql.com/doc/refman/5.1/en/alter-table.html then use the LOAD data infile csv on the table – HashSu Jul 22 '15 at 14:41