-
Notifications
You must be signed in to change notification settings - Fork 0
/
HospitalDBSQL.sql
293 lines (194 loc) · 4.18 KB
/
HospitalDBSQL.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
CREATE DATABASE Hospital
CREATE TABLE Employee
(
ESSN int not null PRIMARY KEY ,
EFName nvarchar(30) not null ,
ELName nvarchar(30) not null ,
EAge int not null ,
ESex nvarchar(10) not null ,
EEmail nvarchar(30) not null ,
Phone nvarchar(13) not null ,
Dept int not null ,
Hired date not null ,
Salary int not null ,
WorkHours int not null
)
CREATE TABLE Doctor
(
ESSN int not Null PRIMARY KEY,
ELName nvarchar(30) not Null ,
HireDate date not NULL ,
YearsOfExp int not null ,
Field nvarchar(30) not null ,
SciDegree nvarchar(30) not null ,
Op int null
)
CREATE TABLE Patient
(
PSSN int not null PRIMARY KEY ,
PFName nvarchar(30) not null ,
PLName nvarchar(30) not null ,
PPAge int not null ,
PSex nvarchar(10) not null ,
PEmail nvarchar(30) not null ,
PPhone nvarchar(13) not null ,
Dignoses nvarchar(100) not null ,
RoomNum int not null ,
EnDate date not null ,
ExpLeave date not null ,
Doctor int not null ,
ExmTime time not null ,
ExmDate date not null ,
ExmPeriod int not null ,
Nurse int not null
)
CREATE TABLE Client
(
CSSN int not null PRIMARY KEY ,
CFName nvarchar(30) not null ,
CLName nvarchar(30) not null ,
CAge int not null ,
Purpose nvarchar(30) not null ,
CEmail nvarchar(30) not null ,
CPhone nvarchar(13) not null
)
CREATE TABLE Nurse
(
ESSN int not null PRIMARY KEY ,
ELName nvarchar(30) not null ,
NShift nvarchar(30) not null ,
Marriage BIT null ,
Supervisor int not null
)
CREATE TABLE HouseKeeper
(
ESSN int not null PRIMARY KEY ,
ELName nvarchar(30) not null ,
WkShift nvarchar(30) not null ,
)
CREATE TABLE Department
(
Dnum int not null PRIMARY KEY ,
DName nvarchar(30) not null ,
Capacity int not null ,
QuOfEmps int null ,
Manager int not null
)
CREATE TABLE Room
(
RoomNo int not null PRIMARY KEY ,
RFloor int not null ,
Capacity int not null ,
RLandLine int null ,
RNurse int not null ,
RHK int not null
)
CREATE TABLE Opration
(
OpID int not Null PRIMARY KEY,
OpName nvarchar(15) not Null ,
ETA int not NULL ,
OpPeriod int not null
)
CREATE TABLE OperationTheater
(
THNum int not Null PRIMARY KEY,
THFloor int not Null ,
Operation int not null
)
CREATE TABLE Clinic
(
CID int not Null PRIMARY KEY,
CName nvarchar(30) not Null ,
CFloor int NULL,
CLandLine int not Null ,
CShift nvarchar(10) not null ,
Specialization int not null ,
Doct int not null
)
CREATE TABLE ICU
(
UnitNum int not Null PRIMARY KEY,
ICUFloor int not Null ,
IcuLandLine int not NULL ,
INurse int not null ,
IHK int not null
)
CREATE TABLE Specialization
(
SpId int not Null PRIMARY KEY,
SpName nvarchar(30) not Null ,
SpAge int NULL ,
SpMAnager int not null
)
Alter table Doctor
add foreign key (Op)
references Opration(OpID)
Alter table Nurse
add foreign key (Supervisor)
references Doctor(ESSN)
Alter table Room
add foreign key (RNurse)
references Nurse(ESSN)
Alter table Room
add foreign key (RHK )
references HouseKeeper (ESSN)
Alter table ICU
add foreign key (INurse)
references Nurse(ESSN)
Alter table ICU
add foreign key (IHK )
references HouseKeeper (ESSN)
Alter table OperationTheater
add foreign key (Operation )
references Opration(OpID)
Alter table Specialization
add foreign key (SpMAnager )
references Doctor(ESSN)
Alter table Patient
add foreign key (RoomNum)
references Room(RoomNo)
Alter table Patient
add foreign key (Nurse)
references Nurse(ESSN)
Alter table Patient
add foreign key (Doctor )
references Doctor(ESSN)
Alter table Clinic
add foreign key (Doct)
references Doctor(ESSN)
Alter table Clinic
add foreign key (Specialization)
references Specialization(SpID)
Alter table Employee
add foreign key (Dept)
references Department(Dnum)
Alter table Department
add foreign key (MAnager )
references Employee(ESSN)
CREATE TABLE Reserve
(
Clinic int not null,
Client int not NULL ,
RsvDate Date not null,
RsvTime Time not null
)
Alter table Reserve
add foreign key (Clinic)
references Clinic(CID)
Alter table Reserve
add foreign key (Client )
references Client (CSSN)
CREATE TABLE Visit
(
Room int not null,
Client int not NULL ,
VstDate Date not null,
VstTime Time not null
)
Alter table Visit
add foreign key (Room)
references Room(RoomNo)
Alter table Visit
add foreign key (Client )
references Client (CSSN)