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
| create table REGION
(
reg_nom CHAR(30) UNIQUE not null,
reg_altitude integer CONSTRAINT Raltitude CHECK (reg_altitude between 0 and 10000),
primary key (reg_nom)
)ENGINE=innoDB;
create table CLIENTS
(
C_num integer UNIQUE not null,
C_nom CHAR(30) not null,
C_CP integer not null,
C_ville CHAR(30) not null,
C_rue CHAR(30) not null,
C_tel integer,
primary key (C_num)
)ENGINE=innoDB;
create table SAISON
(
S_nom CHAR(10) not null CONSTRAINT Nomsaison CHECK (S_nom IN ('printemps', 'été', 'automne', 'hiver')),
S_datedebut DATE,
S_datefin DATE,
primary key (S_nom)
)ENGINE=innoDB;
create table TYPE_CHAMBRE
(
type_typechambre CHAR(10) not null CONSTRAINT Tchambre CHECK (type_typechambre IN ('Suite', 'Simple')),
primary key (type_typechambre)
)ENGINE=innoDB;
create table CATEGORIE_HOTEL
(
CATH_etoile integer not null CONSTRAINT Cathotel CHECK (CATH_etoile between 1 and 5),
primary key (CATH_etoile)
)ENGINE=innoDB;
create table Type_SDB
(
type_typesdb CHAR(10) not null CONSTRAINT Tsdb CHECK (type_typesdb IN ('Privée', 'Publique')),
primary key (type_typesdb)
)ENGINE=innoDB;
create table STATION
(
stat_numero integer UNIQUE not null CONSTRAINT Snum CHECK (stat_numero>0),
reg_nom CHAR(30) not null,
stat_nom CHAR(30) UNIQUE not null,
primary key (stat_numero)
)ENGINE=innoDB;
create table HOTEL
(
H_num integer CHAR(10) UNIQUE not null CONSTRAINT Hnum CHECK (H_num>0),
stat_numero integer not null,
CATH_etoile integer not null,
h_nom CHAR(30) not null,
h_ville CHAR(30) not null,
h_CP integer not null,
h_rue CHAR(30) not null,
primary key (H_num)
)ENGINE=innoDB;
create table CHAMBRE
(
H_num integer not null CONSTRAINT Hnumber CHECK (H_num>0),
ch_num integer not null CONSTRAINT Cnum1 CHECK (ch_num>0),
type_typechambre CHAR(10) not null CONSTRAINT Tchambre2 CHECK (type_typechambre IN ('Suite', 'Simple')),
type_typesdb CHAR(10) not null CONSTRAINT Tsdb2 CHECK (type_typesdb IN ('Privée', 'Publique')),
ch_nblits integer not null CONSTRAINT CHlit CHECK (ch_nblits>0),
primary key (H_num, ch_num)
)ENGINE=innoDB;
create table RESERVATION
(
Res_num integer not null CONSTRAINT Rnum CHECK (Res_num>0),
C_num integer not null CONSTRAINT Cnum2 CHECK (C_num>0),
Res_Nosemaine integer not null CONSTRAINT Cres CHECK (Res_Nosemaine between 1 and 52),
primary key (Res_num)
)ENGINE=innoDB;
create table concerner
(
H_num integer not null,
ch_num integer not null,
Res_num integer not null,
primary key (H_num, ch_num, Res_num)
)ENGINE=innoDB;
create table Tarif
(
S_nom CHAR(10) not null,
H_num integer not null,
ch_num integer not null,
prix CHAR(10) ,
primary key (S_nom, H_num, ch_num)
)ENGINE=innoDB;
create table Abonnement
(
stat_numero integer not null CONSTRAINT Stnum CHECK (stat_numero>0),
C_num integer not null CONSTRAINT Cnum3 CHECK (C_num>0),
datedebut DATE,
Datefin DATE,
pourcentage_remise CHAR(10) CONSTRAINT Premise CHECK (pourcentage_remise between 0 and 1),
primary key (stat_numero, C_num)
)ENGINE=innoDB;
alter table STATION
add foreign key (reg_nom)
references REGION (reg_nom);
alter table HOTEL
add foreign key (stat_numero)
references STATION (stat_numero);
alter table HOTEL
add foreign key (CATH_etoile)
references CATEGORIE_HOTEL (CATH_etoile);
alter table CHAMBRE
add foreign key (H_num)
references HOTEL (H_num);
alter table CHAMBRE
add foreign key (type_typechambre)
references TYPE_CHAMBRE (type_typechambre);
alter table CHAMBRE
add foreign key (type_typesdb)
references Type_SDB (type_typesdb);
alter table RESERVATION
add foreign key (C_num)
references CLIENTS (C_num);
alter table concerner
add foreign key (H_num, ch_num)
references CHAMBRE (H_num, ch_num);
alter table concerner
add foreign key (Res_num)
references RESERVATION (Res_num);
alter table Tarif
add foreign key (S_nom)
references SAISON (S_nom);
alter table Tarif
add foreign key (H_num, ch_num)
references CHAMBRE (H_num, ch_num);
alter table Abonnement
add foreign key (stat_numero)
references STATION (stat_numero);
alter table Abonnement
add foreign key (C_num)
references CLIENTS (C_num); |
Partager