-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtables.sql
More file actions
148 lines (131 loc) · 4.09 KB
/
tables.sql
File metadata and controls
148 lines (131 loc) · 4.09 KB
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
create table if not exists Guests(
g_id int not null AUTO_INCREMENT,
first_name varchar(255) not null,
last_name varchar(255) not null,
username varchar(45) not null unique,
password varchar(255) not null,
primary key(g_id)
);
create table if not exists Employee(
emp_id int not null AUTO_INCREMENT,
first_name varchar(255) not null,
last_name varchar(255) not null,
username varchar(45) not null unique,
password varchar(255) not null,
primary key(emp_id)
);
create table if not exists Emp_contact(
emp_id int not null,
contact_no varchar(12) not null,
primary key(emp_id, contact_no),
foreign key(emp_id) references Employee(emp_id)
);
create table if not exists Emp_email(
emp_id int not null,
email_id varchar(45) not null,
primary key(emp_id, email_id),
foreign key(emp_id) references Employee(emp_id)
);
create table if not exists Department(
dept_id int not null,
dept_name varchar(255) not null,
description varchar(255) default null,
primary key(dept_id)
);
create table if not exists Emp_dept(
emp_id int not null,
dept_id int not null,
primary key(emp_id, dept_id),
foreign key(emp_id) references Employee(emp_id),
foreign key(dept_id) references Department(dept_id)
);
create table if not exists Address(
address_id int not null,
city varchar(45) not null,
state varchar(45) not null,
country varchar(45) not null,
zipcode varchar(6) not null,
primary key(address_id)
);
create table if not exists Guest_address(
g_id int not null,
address_id int not null,
primary key(g_id, address_id),
foreign key(g_id) references Guests(g_id),
foreign key(address_id) references Address(address_id)
);
create table if not exists Emp_address(
emp_id int not null,
address_id int not null,
primary key(emp_id, address_id),
foreign key(emp_id) references Employee(emp_id),
foreign key(address_id) references Address(address_id)
);
create table if not exists Services(
serv_id int not null,
emp_id int not null,
description varchar(255) not null,
cost decimal(10, 2) not null,
primary key(serv_id, emp_id),
foreign key(emp_id) references Employee(emp_id)
);
create table if not exists Room(
room_id int not null,
room_no int not null,
floor_no int not null,
primary key(room_id)
);
create table if not exists Room_type(
room_type_id int not null,
room_type_name varchar(45) not null,
description varchar(255) default null,
cost decimal(10,2) not null,
primary key(room_type_id)
);
create table if not exists room_type_rel(
room_id int not null,
room_type_id int not null,
primary key(room_id, room_type_id),
foreign key(room_id) references Room(room_id),
foreign key(room_type_id) references Room_type(room_type_id)
);
create table if not exists Room_booked(
g_id int not null,
room_id int not null,
b_id int not null,
ratings int check(ratings >=1 and ratings <=5),
primary key(g_id, room_id, b_id),
foreign key(g_id) references Guests(g_id),
foreign key(room_id) references Room(room_id),
foreign key(b_id) references Bookings(b_id)
);
create table if not exists Guests_contact(
g_id int not null,
contact_no varchar(12) not null,
primary key(g_id, contact_no),
foreign key(g_id) references Guests(g_id)
);
create table if not exists Guests_email(
g_id int not null,
email_id varchar(45) not null,
primary key(g_id, email_id),
foreign key(g_id) references Guests(g_id)
);
create table if not exists Service_used(
g_id int not null,
serv_id int not null,
ratings int check(ratings >=1 and ratings <=5),
primary key(g_id, serv_id),
foreign key(g_id) references Guests(g_id),
foreign key(serv_id) references Services(serv_id)
);
create table if not exists Bookings(
b_id int not null,
b_datetime datetime DEFAULT CURRENT_TIMESTAMP,
check_in date not null,
check_out date not null,
payment_type varchar(45) not null,
total_amount decimal(10, 2) not null,
total_rooms int not null,
primary key(b_id)
);