En attente de plus d’informations de votre part, je me limite pour le moment au scénario suivant :
La base de données contient une table PAYS, dont la structure est issue du script suivant :
CREATE TABLE PAYS
(
Id_Pays INTEGER NOT NULL
, Nom_Pays VARCHAR(16) NOT NULL
, CONSTRAINT PAYS_PK PRIMARY KEY (Id_Pays)
) ;
INSERT INTO PAYS (Id_Pays, Nom_Pays) VALUES (1, 'France'), (2, 'Belgique'), (3, 'Canada') ;
Le fichier Excel a été converti au format CSV (les valeurs de la colonne id_pays sont des valeurs existant dans la table PAYS) :
id nom_contact nom_structure id_typologie id_pays
1 Fernand Ets Naudin 3 2
2 Raoul La péniche 1 1
3 Paul La péniche 1 1
Une structure pour héberger ce fichier dans la base de données :
CREATE TABLE imageExcel
(
id INTEGER NOT NULL
, nom_contact VARCHAR(16) NOT NULL
, nom_structure VARCHAR(16) NOT NULL
, id_typologie INTEGER NOT NULL
, id_pays INTEGER NOT NULL
, CONSTRAINT imageExcel_PK PRIMARY KEY (id)
, CONSTRAINT imageExcel_Pays_FK FOREIGN KEY (id_pays)
REFERENCES PAYS (id_pays)
) ;
Importation du fichier CSV (nommé ici « geeka.csv ») :
LOAD DATA INFILE 'C:\Developpez/$MySQL/geeka.csv' INTO TABLE imageExcel
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\r\n'
IGNORE 1 ROWS ;
Pour voir :
SELECT * FROM imageExcel ;
=>
id nom_contact nom_structure id_typologie id_pays
1 Fernand Ets Naudin 3 2
2 Raoul La péniche 1 1
3 Paul La péniche 1 1
Partager