tags:

views:

22

answers:

2

Mysql LOAD command lets import data from csv files

LOAD DATA INFILE 'data.csv' INTO TABLE table_main
  FIELDS TERMINATED BY ',';

What if there are multiple relation tables

table_main
    id
    firstname
    lastname

table_type
    id
    table_main_id
    table_type_id

table_type
    id
    typename        

Is it possible to load a csv file with content like below with LOAD command

firstname, lastname, typename
john,doe,mytypename
+1  A: 

No, it it not possible with LOAD DATA syntax to insert into multiple tables. A possible workaround is loading it into a temporary table & take it from there.

Wrikken
A: 

No, IMHO. You would have to

  • first LOAD to temporary table, then
  • do the 3 INSERT statements and finally
  • DROP the temp table.
Unreason