Filling tables with multiple foreign keys [closed]

2

I have a database with the following tables:

    Airport Airport

  • Cause_Cancelation (CodeCanceling PK , description)

  • Manufacturer (ManufacturerName PK , manufacturername)

    Template (Template ID PK , template_name, FK

  • Aircraft Type (Airplane PK , typeair)

  • Motor_type (motor_type PK , motor_type)

  • FK , FK , FK FK , FT FK , FK , FT_type FK , date_log, state, year)
asked by anonymous 09.08.2015 / 19:25

1 answer

0

In MySQL, you can use a feature of it called LOAD DATA INFILE.

  

The LOAD DATA INFILE statement allows you to read data from a text   file and import the file is very fast.

With it, you can directly load a CSV from your file system and move to a MySQL database table.

If you have a table Aviao (abstract some fields because I do not have the details of your table):

CREATE TABLE Aviao (
  codAviao INT NOT NULL AUTO_INCREMENT,
  data_registro DATE NOT NULL,
  nome VARCHAR(50) NOT NULL
  PRIMARY KEY (codAviao )
);

And a CSV called avioes.csv, with this content:

codAviao, data_registro, nome
1, 20150809, "Aviao 1"
2, 20140809, "Aviao 2"

You can import this way (with the avioes.csv file located in c: / tmp /):

LOAD DATA INFILE 'c:/tmp/avioes.csv' 
INTO TABLE discounts 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

More details you can find here: link

To ensure the integrity of the information at the end of the process, since you (probably) need to insert information from related tables not yet imported into one of the imports, just at the start of the import, disable the foreign key verification:

SET FOREIGN_KEY_CHECKS=0;

and then enable again, at the end of the import:

SET FOREIGN_KEY_CHECKS=1;
    
10.08.2015 / 01:21