-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplementing_a_resort_hotel_data_model.sql
executable file
·206 lines (178 loc) · 6.55 KB
/
implementing_a_resort_hotel_data_model.sql
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
-- Created by Vertabelo (http://vertabelo.com)
-- Last modification date: 2016-10-02 01:15:00.086
-- tables
-- Table: car
CREATE TABLE car (
carID int(4) NOT NULL,
carType varchar(15) NOT NULL,
carColor varchar(10) NOT NULL,
carYear int(4) NOT NULL,
driverNeeded bool NOT NULL,
hotelID int(4) NOT NULL,
CONSTRAINT car_pk PRIMARY KEY (carID)
);
-- Table: carRental
CREATE TABLE carRental (
TimeFrom time NOT NULL,
TimeTo time NOT NULL,
carCount int(2) NOT NULL,
reservationID int(10) NOT NULL,
carID int(4) NOT NULL,
CONSTRAINT carRental_pk PRIMARY KEY (reservationID,carID)
);
-- Table: guest
CREATE TABLE guest (
gID int(4) NOT NULL,
gFName varchar(15) NOT NULL,
gMI varchar(1) NOT NULL,
gLName varchar(25) NOT NULL,
gEmail varchar(15) NOT NULL,
gPassportNo varchar(15) NOT NULL,
gPhoneNo int(14) NOT NULL,
gStreet varchar(25) NOT NULL,
gCity varchar(15) NOT NULL,
gState varchar(2) NOT NULL,
gZip int(5) NOT NULL,
gCountry varchar(25) NOT NULL,
CONSTRAINT guest_pk PRIMARY KEY (gID)
);
-- Table: hotel
CREATE TABLE hotel (
hotelID int(4) NOT NULL,
hotelName varchar(15) NOT NULL,
hotelAddress varchar(25) NOT NULL,
hotelZip varchar(5) NOT NULL,
hotelCity varchar(15) NOT NULL,
hotelState varchar(2) NOT NULL,
hotelStarRating int(7) NOT NULL,
hotelURL varchar(25) NOT NULL,
CONSTRAINT hotel_pk PRIMARY KEY (hotelID)
);
-- Table: reservation
CREATE TABLE reservation (
reservationID int(10) NOT NULL,
dateFrom date NOT NULL,
dateTo date NOT NULL,
amountPaid double(6,2) NOT NULL,
numGuests int(2) NOT NULL,
parkingNeeded bool NOT NULL,
gID int(4) NOT NULL,
CONSTRAINT reservation_pk PRIMARY KEY (reservationID)
);
-- Table: restaurReservation
CREATE TABLE restaurReservation (
rTimeFrom time NOT NULL,
rTimeTo time NOT NULL,
tableCount int(2) NOT NULL,
reservationID int(10) NOT NULL,
restaurID int(4) NOT NULL,
CONSTRAINT restaurReservation_pk PRIMARY KEY (reservationID,restaurID)
);
-- Table: restaurant
CREATE TABLE restaurant (
restaurID int(4) NOT NULL,
restaurName varchar(25) NOT NULL,
michelinStars int(3) NOT NULL,
`table` int(3) NOT NULL,
hotelID int(4) NOT NULL,
cuisine varchar(15) NOT NULL,
CONSTRAINT restaurant_pk PRIMARY KEY (restaurID)
);
-- Table: room
CREATE TABLE room (
roomNo int(5) NOT NULL,
roomFloor int(2) NOT NULL,
roomType varchar(15) NOT NULL,
CONSTRAINT room_pk PRIMARY KEY (roomNo)
);
-- Table: roomReservation
CREATE TABLE roomReservation (
roomCount int(2) NOT NULL,
checkedIn bool NOT NULL,
reservationID int(10) NOT NULL,
roomNo int(5) NOT NULL,
CONSTRAINT roomReservation_pk PRIMARY KEY (reservationID,roomNo)
);
-- Table: roomType
CREATE TABLE roomType (
roomType varchar(15) NOT NULL,
roomStdRate double(5,2) NOT NULL,
roomTypeDesc varchar(35) NOT NULL,
smoking bool NOT NULL,
view varchar(10) NOT NULL,
hotelID int(4) NOT NULL,
CONSTRAINT roomType_pk PRIMARY KEY (roomType)
);
-- Table: spa
CREATE TABLE spa (
spaID int(4) NOT NULL,
spaName varchar(25) NOT NULL,
spaService varchar(25) NOT NULL,
priceSpaService double(5,2) NOT NULL,
hotelID int(4) NOT NULL,
CONSTRAINT spa_pk PRIMARY KEY (spaID)
);
-- Table: spaReservation
CREATE TABLE spaReservation (
spaResID int(10) NOT NULL,
sTimeFrom time NOT NULL,
sTimeTo time NOT NULL,
reservationID int(10) NOT NULL,
spaID int(4) NOT NULL,
CONSTRAINT spaReservation_pk PRIMARY KEY (reservationID,spaID)
);
-- foreign keys
-- Reference: car_hotel (table: car)
ALTER TABLE car ADD CONSTRAINT car_hotel FOREIGN KEY car_hotel (hotelID)
REFERENCES hotel (hotelID)
ON DELETE RESTRICT;
-- Reference: reservation_guest (table: reservation)
ALTER TABLE reservation ADD CONSTRAINT reservation_guest FOREIGN KEY reservation_guest (gID)
REFERENCES guest (gID)
ON DELETE RESTRICT;
-- Reference: restaurReservation_reservation (table: restaurReservation)
ALTER TABLE restaurReservation ADD CONSTRAINT restaurReservation_reservation FOREIGN KEY restaurReservation_reservation (reservationID)
REFERENCES reservation (reservationID)
ON DELETE RESTRICT;
-- Reference: restaurReservation_restaurant (table: restaurReservation)
ALTER TABLE restaurReservation ADD CONSTRAINT restaurReservation_restaurant FOREIGN KEY restaurReservation_restaurant (restaurID)
REFERENCES restaurant (restaurID);
-- Reference: restaurant_hotel (table: restaurant)
ALTER TABLE restaurant ADD CONSTRAINT restaurant_hotel FOREIGN KEY restaurant_hotel (hotelID)
REFERENCES hotel (hotelID)
ON DELETE RESTRICT;
-- Reference: roomReservation_reservation (table: roomReservation)
ALTER TABLE roomReservation ADD CONSTRAINT roomReservation_reservation FOREIGN KEY roomReservation_reservation (reservationID)
REFERENCES reservation (reservationID)
ON DELETE RESTRICT;
-- Reference: roomReservation_room (table: roomReservation)
ALTER TABLE roomReservation ADD CONSTRAINT roomReservation_room FOREIGN KEY roomReservation_room (roomNo)
REFERENCES room (roomNo);
-- Reference: roomType_hotel (table: roomType)
ALTER TABLE roomType ADD CONSTRAINT roomType_hotel FOREIGN KEY roomType_hotel (hotelID)
REFERENCES hotel (hotelID)
ON DELETE RESTRICT;
-- Reference: room_roomType (table: room)
ALTER TABLE room ADD CONSTRAINT room_roomType FOREIGN KEY room_roomType (roomType)
REFERENCES roomType (roomType);
-- Reference: spaReservation_reservation (table: spaReservation)
ALTER TABLE spaReservation ADD CONSTRAINT spaReservation_reservation FOREIGN KEY spaReservation_reservation (reservationID)
REFERENCES reservation (reservationID)
ON DELETE RESTRICT;
-- Reference: spaReservation_spa (table: spaReservation)
ALTER TABLE spaReservation ADD CONSTRAINT spaReservation_spa FOREIGN KEY spaReservation_spa (spaID)
REFERENCES spa (spaID)
ON DELETE RESTRICT;
-- Reference: spa_hotel (table: spa)
ALTER TABLE spa ADD CONSTRAINT spa_hotel FOREIGN KEY spa_hotel (hotelID)
REFERENCES hotel (hotelID)
ON DELETE RESTRICT;
-- Reference: valetReservation_Copy_of_restaurant (table: carRental)
ALTER TABLE carRental ADD CONSTRAINT valetReservation_Copy_of_restaurant FOREIGN KEY valetReservation_Copy_of_restaurant (carID)
REFERENCES car (carID)
ON DELETE RESTRICT;
-- Reference: valetReservation_reservation (table: carRental)
ALTER TABLE carRental ADD CONSTRAINT valetReservation_reservation FOREIGN KEY valetReservation_reservation (reservationID)
REFERENCES reservation (reservationID)
ON DELETE RESTRICT;
-- End of file.