Loading data from file into MySQL table with foreign key constraint -


i need load data file table foreign key constraint. if have parent table populated , want populate child how find appropriate foreign key child. i.e. if have department , employee table employee contains fk_department_id no other identifying information department, how know department employee belongs to. thinking of using temporary tables contained identifying information department (like department name) in employee table , using join appropriate fk's. put info without identifying columns database, don't think best way it.

first load data department table, , after execute following using department name in employee csv, ex.:

department csv: deptname, manager ("finance","ted smith")  department table: de_id, de_name, de_manager  emplstrong textoyee csv: name, surname, deptname ("tom", "smith", "finance")  employee table: em_id, em_name, em_surname, em_de_id  load data low_priority local infile 'c:\\temp\\employee.csv' table `tbl_employees`  fields terminated ',' optionally enclosed '"' escaped '"' lines terminated '\r\n'   (em_name, em_surname,  @colvar3)  set `em_de_id` = (select de_id tbl_departments de_name = @colvar3) 

i have used in mysql 5.1


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -