1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
| --------------
SET AUTOCOMMIT = 0
--------------
--------------
START TRANSACTION
--------------
--------------
DROP DATABASE IF EXISTS `base`
--------------
--------------
CREATE DATABASE `base`
DEFAULT CHARACTER SET `latin1`
DEFAULT COLLATE `latin1_general_ci`
--------------
--------------
DROP TABLE IF EXISTS `pays`
--------------
--------------
CREATE TABLE `pays`
(
`id` integer unsigned NOT NULL AUTO_INCREMENT Primary Key,
`pays` varchar(255) NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `pays` (`id`, `pays`) VALUES
(31, 'Garonne'),
(75, 'Ville de Paris'),
(38, 'Isère'),
(21, 'Côte d''or'),
(24, 'Dordogne'),
(33, 'Gironde')
--------------
--------------
select * from pays
--------------
+----+----------------+
| id | pays |
+----+----------------+
| 21 | Côte d'or |
| 24 | Dordogne |
| 31 | Garonne |
| 33 | Gironde |
| 38 | Isère |
| 75 | Ville de Paris |
+----+----------------+
--------------
DROP TABLE IF EXISTS `ville`
--------------
--------------
CREATE TABLE `ville`
(
`id` integer unsigned NOT NULL AUTO_INCREMENT Primary Key,
`ville` varchar(255) NOT NULL,
`codepostal` integer unsigned NOT NULL,
`pays` integer unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `ville` (`ville`, `codepostal`, `pays`) VALUES
('Toulouse', 31000, 31),
('Paris', 75000, 75),
('Grenoble', 38000, 38),
('Dijon', 21000, 21),
('Périgueux', 24000, 24),
('Bordeaux', 33000, 33)
--------------
--------------
select * from ville
--------------
+----+-----------+------------+------+
| id | ville | codepostal | pays |
+----+-----------+------------+------+
| 1 | Toulouse | 31000 | 31 |
| 2 | Paris | 75000 | 75 |
| 3 | Grenoble | 38000 | 38 |
| 4 | Dijon | 21000 | 21 |
| 5 | Périgueux | 24000 | 24 |
| 6 | Bordeaux | 33000 | 33 |
+----+-----------+------------+------+
--------------
DROP TABLE IF EXISTS `adresse`
--------------
--------------
CREATE TABLE `adresse`
(
`id` integer unsigned NOT NULL AUTO_INCREMENT Primary Key,
`numero` integer unsigned NOT NULL,
`rue` varchar(255) NOT NULL,
`cite` integer unsigned NOT NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `adresse` (`numero`, `rue`, `cite`) VALUES
(15, 'boulevard albert le grand', 1),
(25, 'avenue des champs élysées', 2),
(99, 'impasse saint-denis', 3),
(45, 'boulevard jean-jaures', 4),
(77, 'rue des allongés', 5),
(12, 'route sans issue', 6)
--------------
--------------
select * from adresse
--------------
+----+--------+---------------------------+------+
| id | numero | rue | cite |
+----+--------+---------------------------+------+
| 1 | 15 | boulevard albert le grand | 1 |
| 2 | 25 | avenue des champs élysées | 2 |
| 3 | 99 | impasse saint-denis | 3 |
| 4 | 45 | boulevard jean-jaures | 4 |
| 5 | 77 | rue des allongés | 5 |
| 6 | 12 | route sans issue | 6 |
+----+--------+---------------------------+------+
--------------
DROP TABLE IF EXISTS `client`
--------------
--------------
CREATE TABLE `client`
(
`id` integer unsigned NOT NULL AUTO_INCREMENT Primary Key,
`nom` varchar(255) NOT NULL,
`prenom` varchar(255) NOT NULL,
`domicile` integer unsigned NULL,
`travail` integer unsigned NULL
) ENGINE=InnoDB
DEFAULT CHARSET=`latin1` COLLATE=`latin1_general_ci`
ROW_FORMAT=COMPRESSED
--------------
--------------
INSERT INTO `client` (`nom`, `prenom`,`domicile`,`travail`) VALUES
('nom 1', 'prenom 1', 1, 2),
('nom 2', 'prenom 2', 3, 4),
('nom 3', 'prenom 3', 5, null),
('nom 4', 'prenom 4', null, 6)
--------------
--------------
select * from client
--------------
+----+-------+----------+----------+---------+
| id | nom | prenom | domicile | travail |
+----+-------+----------+----------+---------+
| 1 | nom 1 | prenom 1 | 1 | 2 |
| 2 | nom 2 | prenom 2 | 3 | 4 |
| 3 | nom 3 | prenom 3 | 5 | NULL |
| 4 | nom 4 | prenom 4 | NULL | 6 |
+----+-------+----------+----------+---------+
--------------
select c.id as 'id cli',
c.nom as 'nom cli',
c.prenom as 'prenom cli',
d.id as 'id dom',
d.numero as 'numero dom',
d.rue as 'rue dom',
d.cite as 'id ville dom',
vd.ville as 'ville dom',
vd.codepostal as 'code postal dom',
vd.pays as 'id pays dom',
pd.pays as 'pays dom',
t.id as 'id trav',
t.numero as 'numero trav',
t.rue as 'rue trav',
t.cite as 'id ville trav',
vt.ville as 'ville trav',
vt.codepostal as 'code postal trav',
vt.pays as 'id pays trav',
pt.pays as 'pays trav'
from client as c
left outer join adresse as d
on d.id = c.domicile
left outer join adresse as t
on t.id = c.travail
left outer join ville as vd
on vd.id = d.cite
left outer join ville as vt
on vt.id = t.cite
left outer join pays as pd
on pd.id = vd.pays
left outer join pays as pt
on pt.id = vt.pays
--------------
+--------+---------+------------+--------+------------+---------------------------+--------------+-----------+-----------------+-------------+----------+---------+-------------+---------------------------+---------------+------------+------------------+--------------+----------------+
| id cli | nom cli | prenom cli | id dom | numero dom | rue dom | id ville dom | ville dom | code postal dom | id pays dom | pays dom | id trav | numero trav | rue trav | id ville trav | ville trav | code postal trav | id pays trav | pays trav |
+--------+---------+------------+--------+------------+---------------------------+--------------+-----------+-----------------+-------------+----------+---------+-------------+---------------------------+---------------+------------+------------------+--------------+----------------+
| 1 | nom 1 | prenom 1 | 1 | 15 | boulevard albert le grand | 1 | Toulouse | 31000 | 31 | Garonne | 2 | 25 | avenue des champs élysées | 2 | Paris | 75000 | 75 | Ville de Paris |
| 2 | nom 2 | prenom 2 | 3 | 99 | impasse saint-denis | 3 | Grenoble | 38000 | 38 | Isère | 4 | 45 | boulevard jean-jaures | 4 | Dijon | 21000 | 21 | Côte d'or |
| 3 | nom 3 | prenom 3 | 5 | 77 | rue des allongés | 5 | Périgueux | 24000 | 24 | Dordogne | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 4 | nom 4 | prenom 4 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | 6 | 12 | route sans issue | 6 | Bordeaux | 33000 | 33 | Gironde |
+--------+---------+------------+--------+------------+---------------------------+--------------+-----------+-----------------+-------------+----------+---------+-------------+---------------------------+---------------+------------+------------------+--------------+----------------+
--------------
COMMIT
--------------
--------------
SET AUTOCOMMIT = 1
--------------
Appuyez sur une touche pour continuer... |
Partager