-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddl.sql
371 lines (286 loc) · 11 KB
/
ddl.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/env sql
# -*- coding: utf-8 -*-
/*
- ===================================
Created: Fri Sep 27 13:16:17 2017
Author: saviokay
Description: The project revolves around designing a database system for an online accommodation
& hospitality company service. We achieve this by designing the database, inserting sample data
& implement a set of required features. Each feature will be implemented as one or more Oracle PL/SQL procedures.
- ===================================
*/
/*
--Drop Commands :
Initially declared to avoid prior data redundancies and issues.
*/
drop table message;
drop table Review;
drop table Payout_Info;
drop table Booking_Info;
drop table Available_Table;
drop table Listing;
drop table Guest;
drop table Host;
drop table Users;
/*
--Create Commands:
Declared for creating Datasbase Schema according to project guidelines.
*/
/*
-- Table Users:
Creating Table User with various attributes like user_id, name, address, phone etc. user_id is declared as a primary key whereas host_id is declared.
*/
create table users
(user_id int,
name char(50),
address varchar(100),
phone_number varchar(20),
email varchar(50),
password varchar(20),
user_type char(5),
primary key(user_id));
/*
-- Table Host:
Creating Table Host with various attributes like host_id, user_id, name, address, phone_number etc. host_id is declared as a primary key whereas user_id is declared as the foreign key.
*/
create table host
(host_id int,
user_id int,
name char(50),
address varchar(100),
phone_number varchar(20),
email varchar(50),
password varchar(20),
avg_rating number(3,2),
account_number varchar(30),
primary key (host_id),
foreign key (user_id) references users (user_id));
create table guest
(guest_id int,
user_id int,
name varchar(50),
address varchar(100),
email varchar (50),
password varchar(20),
phone_number varchar(20),
avg_rating number(3,2),
profile varchar(20),
primary key (guest_id),
foreign key (user_id) references users (user_id));
/*
-- aminitiesType:
Declaring custom TYPE for specific category of aminitiesType for the Table Listing. This type helps store
various services provided by the listing which is added to the table in type 'VARCHAR'.
Using 'CREATE OR REPLACE' to help create with overriding properties.
*/
CREATE OR REPLACE TYPE aminitiesType AS VARRAY(20) OF VARCHAR(50);
/*
-- Table Listing:
Creating Table Listing with various attributes like listing_id, host_id, address, city etc. Listing_Id is declared as a primary key whereas host_id is declared as a foreign key to provide the reference with the Table Host.
*/
create table listing
(listing_id int,
host_id int,
address varchar(100),
city varchar(100),
state varchar(100),
zip_code varchar(150),
building_type varchar (50),
max_capacity int,
number_bedroom int,
number_beds int,
number_bathroom int,
min_num_nightstay int,
check_in_time varchar(20),
check_out_time varchar(20),
aminities aminitiesType,
primary key (listing_id),
foreign key (host_id) references host (host_id));
/*
-- Table Available:
Creating Table Availability with various attributes like listing_id, start_date, end_date, price_per_night etc. avail_id is declared as a primary key whereas listing_id is declared as a foreign key to provide the reference with the Table Host.
*/
create table available_table
(avail_id int,
listing_id,
start_date date,
end_date date,
price_per_night float,
primary key (avail_id),
foreign key (listing_id) references listing (listing_id));
/*
-- Table Booking Info:
Creating Table Booking Info with various attributes like listing_id, guest_id, listing_id, payment_method etc. booking_id is declared as a primary key whereas guest_id & listing_id are declared as a foreign key to provide the reference with the Table Host.
*/
create table booking_info
(booking_id int,
guest_id int,
listing_id int,
check_in_date date,
check_out_date date,
number_adult int,
number_children int,
payment_method varchar (20),
payment_date timestamp,
booking_status varchar(20),
payout_status int,
total_price float,
primary key (booking_id),
foreign key (guest_id) references guest (guest_id),
foreign key (listing_id) references listing (listing_id));
/*
-- Table Payout Info:
Creating Table Payout Info with various attributes like listing_id, guest_id, payout_id, payout_status etc. payout_id is declared as a primary key whereas guest_id & host_id are declared as a foreign key to provide the reference with the Table Host.
*/
create table payout_info
(payout_id int,
host_id int,
payout_date timestamp,
payout_status int,
total_amount float,
primary key (payout_id),
foreign key (host_id) references host (host_id));
/*
-- Table Review:
Creating Table Review with various attributes like review_id, guest_id, host_id, review etc. review_id is declared as a primary key whereas guest_id & host_id are declared as a foreign key to provide the reference with the Table Host.
*/
create table review
(review_id int,
guest_id int,
host_id int,
review varchar (1000),
rating float,
reviewer_type char(1),
primary key (review_id),
foreign key (guest_id) references guest ( guest_id),
foreign key (host_id) references host (host_id));
/*
-- Table Message:
Creating Table Message with various attributes like msg_id, user_id, msg_date, msg_body etc. msg_id is declared as a primary key whereas user_id is declared as a foreign key to provide the reference with the Table Host.
*/
create table message
(msg_id int,
user_id int,
msg_date date, msg_body varchar (1000),
primary key (msg_id),
foreign key (user_id) references users (user_id));
/* Users
Name Null? Type
------------ -------- ------------
USER_ID NUMBER(38,0)
NAME CHAR(50 BYTE)
ADDRESS VARCHAR2(100 BYTE)
PHONE_NUMBER VARCHAR2(20 BYTE)
EMAIL VARCHAR2(50 BYTE)
PASSWORD VARCHAR2(20 BYTE)
USER_TYPE CHAR(5 BYTE) */
--Drop Sequences
Drop sequence AVAILABILITYID;
Drop sequence BOOK_SEQ1;
Drop sequence LISTID_SEQ;
Drop sequence MESSAGEID;
Drop sequence PAYOUTID;
Drop sequence REGISTERUSER;
Drop sequence REVIEWID;
Drop sequence hostseq;
Drop sequence guestseq;
/*
-- Sequence Commands:
Sequence is a feature supported by some database systems to produce unique values on demand. Some DBMS like MySQL supports AUTO_INCREMENT in place of Sequence.
*/
create sequence hostseq start with 200 increment by 1;
create sequence guestseq start with 300 increment by 1;
create sequence AVAILABILITYID start with 1 increment by 1;
create sequence MESSAGEID start with 1 increment by 1;
create sequence PAYOUTID start with 1 increment by 1;
create sequence REGISTERUSER start with 110 increment by 1;
create sequence BOOK_SEQ1 start with 5000 increment by 1;
create sequence LISTID_SEQ start with 1000 increment by 1;
create sequence REVIEWID start with 1 increment by 1;
--Inserting Initial Values
/*
-- Insert Commands:
Insert Commands is a feature supported by some database systems to store in specific values. The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. But make sure the order of the values is in the same order as the columns in the table.
*/
insert into users values (
REGISTERUSER.nextval,'John Doe','123 6th St. Melbourne, FL 32904',
'+1202555-0172','john.doe@gmail.com','john123', 'host');
insert into users values (
REGISTERUSER.nextval,'Emelia Oberbrunner III','71 Pilgrim Avenue Chevy Chase, MD 20815',
'+12025550167','emober3@gmail.com','password123','guest'
);
insert into users values (
REGISTERUSER.nextval,'Craig Reilly','70 Bowman St.South Windsor, CT 06074',
'+12025550125','craigr311@gmail.com','oreilly987','both');
insert into users values (
REGISTERUSER.nextval,'Kevin Leandro','44 Shirley Ave.West Chicago, IL 60185, CT 06074',
'+12025550179','kevin97@gmail.com','qwertty!23','guest');
insert into users values (
REGISTERUSER.nextval,'Gabriel-Auguste Côté','514 S. Magnolia St.Orlando, FL 32806, CT 06074',
'+12025550172','gabbyc@gmail.com','mettsrockz','host');
insert into users values (
REGISTERUSER.nextval,'Jerome D. Levi','1093 Stratford Court Raleigh, NC 27601',
'+19197559586','jerome3@gmail.com','password123','guest');
insert into users values (
REGISTERUSER.nextval,'George C. Williams','2635 Happy Hollow Road Clinton, NC 28328',
'+19105920324','georgec@gmail.com','jesus123','host'
);
insert into users values (
REGISTERUSER.nextval,'Jacqueline E. Torres','4894 Worthington Drive Dallas, TX 75201',
'+19726165405','jacq56@gmail.com','jaccq64','guest'
);
insert into users values (
REGISTERUSER.nextval,'Joan J. Sawyer','743 Spinnaker Lane Lisbon, IL 60541',
'+18157363098','joan.j@gmail.com','i5qt123','host'
);
insert into users values (
REGISTERUSER.nextval,'Rita R. Torres','2022 Adonais Way Newnan, GA 30263',
'+16784236467','ritat1@gmail.com','password123','guest'
);
/* Host
/*
-- Host Insert Commands:
Insert Commands is a feature supported by some database systems to store in specific values. The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. But make sure the order of the values is in the same order as the columns in the table.
Name Null? Type
-------------- -------- ------------
HOST_ID NUMBER(38,0)
USER_ID NUMBER(38,0)
NAME CHAR(50 BYTE)
ADDRESS VARCHAR2(100 BYTE)
PHONE_NUMBER VARCHAR2(20 BYTE)
EMAIL VARCHAR2(50 BYTE)
PASSWORD VARCHAR2(20 BYTE)
AVG_RATING FLOAT
ACCOUNT_NUMBER VARCHAR2(30 BYTE) */
insert into Host values (1
hostseq.nextval,110,'John Doe','123 6th St. Melbourne, FL 32904',
'+1202555-0172','john.doe@gmail.com','john123',0.0,'498077A'
);
insert into Host values (
hostseq.nextval,112,'Craig Reilly','70 Bowman St.South Windsor, CT 06074',
'+12025550125','craigr311@gmail.com','oreilly987',0.0,'471639C'
);
insert into Host values (
hostseq.nextval,114,'Gabriel-Auguste Côté','514 S. Magnolia St.Orlando, FL 32806, CT 06074',
'+12025550172','gabbyc@gmail.com','mettsrockz',0.0,'471325F'
);
insert into Host values (
hostseq.nextval,116,'George C. Williams','2635 Happy Hollow Road Clinton, NC 28328',
'+19105920324','georgec@gmail.com','jesus123',0.0,'789358F'
);
insert into Host values (
hostseq.nextval,118,'Joan J. Sawyer','743 Spinnaker Lane Lisbon, IL 60541',
'+18157363098','joan.j@gmail.com','i5qt123',0.0,'987543D'
);
insert into Host values (
hostseq.nextval,119,'Tom Sawyer','9 Christ Lane, OH 60541',
'+14567364093','tom.s@gmail.com','iasfas12',0.0,'987358F'
);
insert into Host values (
hostseq.nextval,119,'Tom Sawyer','9 Christ Lane, OH 60541',
'+14567364093','tom.s@gmail.com','iasfas12',0.0,'987358F'
);insert into Host values (
hostseq.nextval,119,'Tom Sawyer','9 Christ Lane, OH 60541',
'+14567364093','tom.s@gmail.com','iasfas12',0.0,'987358F'
);
COMMIT;