.
TP n° : GESTION DES DONNES AVEC DES FICHIERS
.
INSERT , INTO , VALUES, PRIMARY KEY
Création de la table DEPARTEMENT
.
Création de la table REGION
.
CREATE | |
---|---|
La syntaxe se comprend aisément. La seule difficulté est de choisir correctement le type de chaque attribut. |
FICHIER CSV : Region.csv
.
Il faut l’ouvrir avec Bloc-Notes et obtenir cet aspect du fichier ,on l’enregistre reg.text
Auvergne-Rhône-Alpes;12;Lyon; |
Bourgogne-Franche-Comté;8;Dijon; |
Bretagne;4;Rennes; |
Centre-Val de Loire;6;Orléans; |
Corse;2;Ajaccio; |
Grand Est;9;Strasbourg; |
Hauts-de-France;5;Lille; |
Île-de-France;8;Paris; |
Normandie;5;Rouen; |
Nouvelle-Aquitaine;12;Bordeaux; |
Occitanie;13;Toulouse; |
Pays de la Loire;5;Nantes; |
Provence-Alpes-Côte d’Azur;6;Marseille; |
.
Il faut le transformer avec un script python trensregion.py
.
fichier1.close()
.
Voici le fichier region.txt
.
insert into REGION (nom,departement,capitale) values (“Auvergne-Rhône-Alpes”,12,”Lyon”);
insert into REGION (nom,departement,capitale) values (“Bourgogne-Franche-Comté”,8,”Dijon”);
insert into REGION (nom,departement,capitale) values (“Bretagne”,4,”Rennes”);
insert into REGION (nom,departement,capitale) values (“Centre-Val de Loire”,6,”Orléans”);
insert into REGION (nom,departement,capitale) values (“Corse”,2,”Ajaccio”);
insert into REGION (nom,departement,capitale) values (“Grand Est”,9,”Strasbourg”);
insert into REGION (nom,departement,capitale) values (“Hauts-de-France”,5,”Lille”);
insert into REGION (nom,departement,capitale) values (“Île-de-France”,8,”Paris”);
insert into REGION (nom,departement,capitale) values (“Normandie”,5,”Rouen”);
insert into REGION (nom,departement,capitale) values (“Nouvelle-Aquitaine”,12,”Bordeaux”);
insert into REGION (nom,departement,capitale) values (“Occitanie”,13,”Toulouse”);
insert into REGION (nom,departement,capitale) values (“Pays de la Loire”,5,”Nantes”);
insert into REGION (nom,departement,capitale) values (“Provence-Alpes-Côte d’Azur”,6,”Marseille”);
.
on execute la commmande
.
INSERT , INTO | VALUES, PRIMARY KEY |
---|---|
La syntaxe se comprend aisément. La seule difficulté est de choisir correctement le type de chaque attribut. |
,
insert into REGION (nom,departement,capitale) values (“Auvergne-Rhône-Alpes”,12,”Lyon”);
insert into REGION (nom,departement,capitale) values (“Bourgogne-Franche-Comté”,8,”Dijon”);
insert into REGION (nom,departement,capitale) values (“Bretagne”,4,”Rennes”);
insert into REGION (nom,departement,capitale) values (“Centre-Val-de-Loire”,6,”Orléans”);
insert into REGION (nom,departement,capitale) values (“Corse”,2,”Ajaccio”);
insert into REGION (nom,departement,capitale) values (“Grand-Est”,9,”Strasbourg”);
insert into REGION (nom,departement,capitale) values (“Hauts-de-France”,5,”Lille”);
insert into REGION (nom,departement,capitale) values (“Île-de-France”,8,”Paris”);
insert into REGION (nom,departement,capitale) values (“Normandie”,5,”Rouen”);
insert into REGION (nom,departement,capitale) values (“Nouvelle-Aquitaine”,12,”Bordeaux”);
insert into REGION (nom,departement,capitale) values (“Occitanie”,13,”Toulouse”);
insert into REGION (nom,departement,capitale) values (“Pays de la Loire”,5,”Nantes”);
insert into REGION (nom,departement,capitale) values (“Provence-Alpes-Côte d-Azur”,6,”Marseille”);
.
Il faut rajouter pour créer et
Code SQL : |
Ébauche de table |
---|---|
.
Création de la table DEPARTEMENT
.
code |
Résultat : |
---|---|
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Val-de-Marne”,253,”Île-de-France”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Val-d-Oise”,254,”Île-de-France”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Calvados”,255,”Normandie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Eure”,256,”Normandie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Manche”,257,”Normandie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Orne”,258,”Normandie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Seine-Maritime”,259,”Normandie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Charente”,260,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Charente-Maritime”,261,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Corrèze”,262,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Creuse”,263,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Dordogne”,264,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Gironde”,265,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Landes”,266,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Lot-et-Garonne”,267,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Pyrénées-Atlantiques”,268,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Deux-Sèvres”,269,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Vienne”,270,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Haute-Vienne”,271,”Nouvelle-Aquitaine”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Ariège”,272,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Aude”,273,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Aveyron”,274,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Gard”,275,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Haute-Garonne”,276,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Gers”,277,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Hérault”,278,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Lot”,279,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Lozère”,280,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Hautes-Pyrénées”,281,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Pyrénées-Orientales”,282,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Tarn”,283,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Tarn-et-Garonne”,284,”Occitanie”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Loire-Atlantique”,285,”Pays de la Loire”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Maine-et-Loire”,286,”Pays de la Loire”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Mayenne”,287,”Pays de la Loire”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Sarthe”,288,”Pays de la Loire”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Vendée”,289,”Pays de la Loire”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Alpes-de-Haute-Provence”,290,”Provence-Alpes-Côte d-Azur”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Hautes-Alpes”,291,”Provence-Alpes-Côte d-Azur”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Alpes-Maritimes”,292,”Provence-Alpes-Côte d-Azur”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Bouches-du-Rhône”,293,”Provence-Alpes-Côte d-Azur”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Var”,294,”Provence-Alpes-Côte d-Azur”); |
insert into DEPARTEMENT (nomeped,nombre,nome) values (“Vaucluse”,295,”Provence-Alpes-Côte d-Azur”); |
.
Création de la table VILLE
.
A vous de jouer !
n_ville |
nu dep |
habitant |
surface |
---|---|---|---|
PARIS |
75 |
2211000 |
105.4 |
MARSEILLE |
13 |
851400 |
240.62 |
LYON |
69 |
474900 |
47.87 |
TOULOUSE |
31 |
439600 |
118.3 |
NICE |
6 |
344900 |
71.92 |
NANTES |
44 |
283300 |
65.19 |
STRASBOURG |
67 |
272100 |
78.26 |
MONTPELLIER |
34 |
253000 |
56.88 |
BORDEAUX |
33 |
235900 |
49.36 |
LILLE |
59 |
225800 |
34.83 |
RENNES |
35 |
206700 |
50.39 |
REIMS |
51 |
181500 |
46.9 |
LE HAVRE |
76 |
178800 |
46.95 |
SAINT-ETIENNE |
42 |
172700 |
79.97 |
TOULON |
83 |
166700 |
42.84 |
GRENOBLE |
38 |
156700 |
18.13 |
DIJON |
21 |
151600 |
40.41 |
ANGERS |
49 |
148400 |
42.7 |
LE MANS |
72 |
143500 |
52.81 |
AIX-EN-PROVENCE |
13 |
142700 |
186.08 |
BREST |
29 |
142100 |
49.51 |
VILLEURBANNE |
69 |
141100 |
14.52 |
NIMES |
30 |
140300 |
161.85 |
LIMOGES |
87 |
140100 |
78.03 |
CLERMONT-FERRAND |
63 |
139000 |
42.67 |
TOURS |
37 |
135500 |
34.67 |
AMIENS |
80 |
134400 |
49.46 |
METZ |
57 |
122800 |
41.94 |
BESANCON |
25 |
117600 |
65.05 |
PERPIGNAN |
66 |
116700 |
68.07 |
ORLEANS |
45 |
113300 |
27.48 |
BOULOGNE-BILLANCOURT |
92 |
112200 |
6.17 |
MULHOUSE |
68 |
111900 |
22.18 |
CAEN |
14 |
109900 |
25.7 |
ROUEN |
76 |
109400 |
21.38 |
NANCY |
54 |
106400 |
15.01 |
SAINT-DENIS |
93 |
103700 |
12.36 |
ARGENTEUIL |
95 |
103300 |
17.22 |
MONTREUIL |
93 |
102200 |
8.92 |
ROUBAIX |
59 |
95900 |
13.23 |
DUNKERQUE |
59 |
93600 |
43.89 |
TOURCOING |
59 |
92600 |
15.19 |
AVIGNON |
84 |
90100 |
64.91 |
NANTERRE |
92 |
89600 |
12.19 |
POITIERS |
86 |
89300 |
42.11 |
CRETEIL |
94 |
89300 |
11.46 |
VERSAILLES |
78 |
86700 |
26.18 |
COURBEVOIE |
92 |
85100 |
4.17 |
VITRY-SUR-SEINE |
94 |
84100 |
11.67 |
PAU |
64 |
84000 |
31.51 |
COLOMBES |
92 |
83700 |
7.81 |
AULNAY-SOUS-BOIS |
93 |
82200 |
16.2 |
ASNIERES-SUR-SEINE |
92 |
81700 |
4.82 |
RUEIL-MALMAISON |
92 |
78100 |
14.7 |
ANTIBES |
6 |
77000 |
26.48 |
LA ROCHELLE |
17 |
75800 |
28.43 |
SAINT-MAUR-DES-FOSSES |
94 |
75700 |
11.25 |
CHAMPIGNY-SUR-MARNE |
94 |
75100 |
11.3 |
CALAIS |
62 |
74800 |
33.5 |
AUBERVILLIERS |
93 |
74500 |
5.76 |
CANNES |
6 |
72900 |
19.62 |
BEZIERS |
34 |
71700 |
95.48 |
BOURGES |
18 |
69000 |
68.74 |
COLMAR |
68 |
66900 |
66.57 |
SAINT-NAZAIRE |
44 |
66900 |
46.79 |
DRANCY |
93 |
66200 |
7.76 |
MERIGNAC |
33 |
66100 |
48.17 |
AJACCIO |
2A |
65200 |
82.03 |
VALENCE |
26 |
64500 |
36.69 |
QUIMPER |
29 |
63900 |
84.45 |
ISSY-LES-MOULINEAUX |
92 |
63300 |
4.25 |
NOISY-LE-GRAND |
93 |
63100 |
12.95 |
LEVALLOIS-PERRET |
92 |
63000 |
2.41 |
VILLENEUVE-D’ASCQ |
59 |
62700 |
27.46 |
TROYES |
10 |
61500 |
13.2 |
ANTONY |
92 |
61200 |
9.56 |
NEUILLY-SUR-SEINE |
92 |
60300 |
3.73 |
LA SEYNE-SUR-MER |
83 |
60000 |
22.17 |
SARCELLES |
95 |
59200 |
8.45 |
CLICHY |
92 |
58400 |
3.08 |
NIORT |
79 |
58100 |
68.2 |
LORIENT |
56 |
58100 |
17.48 |
VENISSIEUX |
69 |
57600 |
15.33 |
PESSAC |
33 |
57600 |
38.82 |
CHAMBERY |
73 |
56800 |
20.99 |
SAINT-QUENTIN |
2 |
56800 |
22.56 |
IVRY-SUR-SEINE |
94 |
56700 |
6.1 |
CERGY |
95 |
56100 |
11.65 |
MONTAUBAN |
82 |
56000 |
135.17 |
HYERES |
83 |
55100 |
132.38 |
BEAUVAIS |
60 |
55000 |
33.31 |
CHOLET |
49 |
54100 |
87.47 |
BONDY |
93 |
53300 |
5.47 |
VILLEJUIF |
94 |
53200 |
5.34 |
VANNES |
56 |
53000 |
32.3 |
MAISONS-ALFORT |
94 |
52900 |
5.35 |
FONTENAY-SOUS-BOIS |
94 |
52800 |
5.58 |
CHELLES |
77 |
52800 |
15.9 |
FREJUS |
83 |
52700 |
102.27 |
PANTIN |
93 |
52700 |
5.01 |
EPINAY-SUR-SEINE |
93 |
52700 |
4.57 |
ARLES |
13 |
52700 |
758.93 |
EVRY |
91 |
52500 |
8.33 |
LA ROCHE-SUR-YON |
85 |
51700 |
87.52 |
GRASSE |
6 |
51600 |
44.44 |
CLAMART |
92 |
51400 |
8.77 |
SARTROUVILLE |
78 |
51400 |
8.46 |
NARBONNE |
11 |
51000 |
172.96 |
CHARLEVILLE-MEZIERES |
8 |
50900 |
31.44 |
LAVAL |
53 |
50900 |
34.22 |
EVREUX |
27 |
50800 |
26.46 |
SEVRAN |
93 |
50800 |
7.28 |
LE BLANC-MESNIL |
93 |
50700 |
8.05 |
BELFORT |
90 |
50300 |
17.1 |
ANNECY |
74 |
50100 |
13.65 |