terencepires
asked on
import data from csv to selected rows in table
hello,
i created a csv file containing data i want to insert in a table. I have 5 rows in the table and want to update only 4, the fifth one is in fact an auto-inc. But when using the import function, phpmyadmin tells me there is a problem at line 1 in my csv file... It works perfectly though when the number of rows in the csv matches the number of rows in the table...
Anyone knows how to do it ?
Cheers
Terence
i created a csv file containing data i want to insert in a table. I have 5 rows in the table and want to update only 4, the fifth one is in fact an auto-inc. But when using the import function, phpmyadmin tells me there is a problem at line 1 in my csv file... It works perfectly though when the number of rows in the csv matches the number of rows in the table...
Anyone knows how to do it ?
Cheers
Terence
ASKER
so if i get you right, i should :
- sort the data in my csv file to match the order of the rows in my table
- import the csv and specify that the line 1 should be ignored
After doing this i get the same error...
- sort the data in my csv file to match the order of the rows in my table
- import the csv and specify that the line 1 should be ignored
After doing this i get the same error...
could you post few lines of your csv, and the result of SHOW CREATE TABLE yourtable
ASKER
csv lines (i used ! as an encloser) :
!54 Nude Honeys!;!(CD 62268-2)!;!3!;!27!;!cd.gif !
!Bandits Mancho!;!(2003 CD 62 278 2)!;!9!;!27!;!cd.gif!
!Retro Sexual!;!(CD 62 266 2!;!13!;!27!;!cd.gif!
SHOW CREATE TABLE result :
CREATE TABLE `temp_products` (\n `products_name_temp` varchar(100) NOT NULL,\n `products_model_temp` varchar(12) NOT NULL default 'ref',\n `manufacturers_id_temp` varchar(11) NOT NULL,\n `categories_id_temp` varchar(11) NOT NULL,\n `product_image_temp` varchar(100) default NULL,\n `products_id_temp` int(11) NOT NULL auto_increment,\n `date_added_temp` timestamp NOT NULL default CURRENT_TIMESTAMP,\n PRIMARY KEY (`products_id_temp`)\n) ENGINE=MyISAM AUTO_INCREMENT=1050 DEFAULT CHARSET=latin1
!54 Nude Honeys!;!(CD 62268-2)!;!3!;!27!;!cd.gif
!Bandits Mancho!;!(2003 CD 62 278 2)!;!9!;!27!;!cd.gif!
!Retro Sexual!;!(CD 62 266 2!;!13!;!27!;!cd.gif!
SHOW CREATE TABLE result :
CREATE TABLE `temp_products` (\n `products_name_temp` varchar(100) NOT NULL,\n `products_model_temp` varchar(12) NOT NULL default 'ref',\n `manufacturers_id_temp` varchar(11) NOT NULL,\n `categories_id_temp` varchar(11) NOT NULL,\n `product_image_temp` varchar(100) default NULL,\n `products_id_temp` int(11) NOT NULL auto_increment,\n `date_added_temp` timestamp NOT NULL default CURRENT_TIMESTAMP,\n PRIMARY KEY (`products_id_temp`)\n) ENGINE=MyISAM AUTO_INCREMENT=1050 DEFAULT CHARSET=latin1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for that !
if you run it using load data infile :
LOAD DATA INFILE ... IGNORE 1 LINES ...
see this for details :
http://dev.mysql.com/doc/refman/5.0/en/load-data.html