Link to home
Start Free TrialLog in
Avatar of vinnystp
vinnystp

asked on

LOAD DATA INFILE into multiple tables with one statement

I have a .csv file I need to have loaded into a mySql database version 4.0.18.

The database is rather new, and empty of data as of right now.

I am interested in using the LOAD DATA INFILE command to import the data from the csv file into the database tables.

In the .csv file I have the following information:
Column
Hotel_Name      - Hotel Table
CheckIn_Date      - Reservation Table
CheckOut_Date      - Reservation Table
Room_Type      - Room Table
Room_Rate      - Room Table
Sabre_Code      - Reservation Table
Reservation_Number      - Reservation Table
Cancellation_Number      - Cancellation Table

There are hundreds of rows in the csv file, so it is not feasable to do an insert statement to put each record into the database.

I can't seem to find the correct syntax to insert data into multiple tables from one LOAD DATA INFILE command.  Is this possible?

I have tried to using this, but I get a Syntax error.

LOAD DATA INFILE 'c:/hoteldata.csv' REPLACE
   INTO TABLE hotel
   FIELDS TERMINATED BY ','
        WHEN hotel_name != ''
   ( hotel_name )
   INTO TABLE reservation
   FIELDS TERMINATED BY ','
        WHEN checkin_date != ''
   (  checkin_date )
   INTO TABLE reservation
   FIELDS TERMINATED BY ','
        WHEN checkout_date != ''
   (  checkout_date )
   INTO TABLE room
   FIELDS TERMINATED BY ','
        WHEN room_type != ' '
   (  room_type )
   INTO TABLE room
   FIELDS TERMINATED BY ','
        WHEN room_rate != ' '
   (  room_rate )
   INTO TABLE reservation
   FIELDS TERMINATED BY ','
        WHEN sabre_code != ' '
   (  sabre_code )
   INTO TABLE reservation
   FIELDS TERMINATED BY ','
        WHEN reservation_id != ' '
   (  reservation_id );

I have also tried this, but same result Syntax error:
LOAD DATA INFILE 'c:/hoteldata.csv' INTO TABLE hotel FIELDS TERMINATED BY ','
     TEXT_FIELDS (text_field1, text_field2, text_field3, text_field4, text_field5, text_field6, text_field7)
     SET hotel_name=CONCAT(text_field1)
     IGNORE (text_field2, text_field3, text_field4, text_field5, text_field6, text_field7);

Any ideas on how to handle inserting data into multiple tables from one file, with one statement?
Or am I going to have to do this with a couple of LOAD DATA INFILE statements?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of petoskey-001
petoskey-001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of petoskey-001
petoskey-001

Oracle can do what you want, but not MySql.  You can use update with multiple tables with MySql 4 or better once your table is imported.
u can try using the DTS package. using that u may be able to load data into multiple tables.

help is available on the net easily :-)

cheers
Parag.
Avatar of vinnystp

ASKER

Sorry for the delay, been super busy writing all this SQL code to handle this functionality.

Ended up creating a temp table to load the data into, then used Insert/Update statements to update the other tables.

Thanks for the help.