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?
Asked
Active
Viewed 1,274 times
-1

Kousik
- 21,485
- 7
- 36
- 59

only chande
- 99
- 2
- 10
-
http://stackoverflow.com/questions/3164505/mysql-insert-record-if-not-exists-in-table – Evadecaptcha Jul 22 '15 at 14:25
-
i am inserting data to mysql via import CSV file – only chande Jul 22 '15 at 14:28
1 Answers
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,507
- 1
- 13
- 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