-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTable.php
280 lines (250 loc) · 7.34 KB
/
createTable.php
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
<?php
$connection = mysqli_connect('localhost','root','');
mysqli_select_db($connection,'EMS_DB')or die("Error occurred");
# Student table
$sql="create table student
(std_ID varchar(20),
first_name varchar(50) not null,
mid_name varchar(50),
last_name varchar(50),
gender varchar(10),
DoB date not null,
street_no varchar(20),
street_name varchar(50),
city varchar(100),
district varchar(100),
achievements text,
primary key(std_ID),
check (gender in ('male','female')))";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table student: ');
}
echo "Table student created successfully\n";
# School table
$sql="create table school
(sch_ID varchar(10) ,
sch_name varchar(100) not null,
street_no varchar(20),
street_name varchar(100),
city varchar(50),
district varchar(50),
number_of_vacancies numeric(4),
primary key (sch_ID)
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table school created successfully\n";
# Applicant table
$sql="create table applicant
(application_ID varchar(20),
first_name varchar(100) not null,
mid_name varchar(100),
last_name varchar(100),
gender varchar(10),
DoB date not null,
mother_fName varchar(100),
mother_LName varchar(100),
father_fName varchar(100),
father_LName varchar(100),
guardian_fName varchar(100),
guardian_LName varchar(100),
primary key (application_ID),
check (gender in ('male','female'))
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table applicant created successfully\n";
#Refer table
$sql="create table refer
(application_ID varchar(20),
std_ID varchar(20),
reference_type varchar(50),
primary key (application_ID,std_ID,reference_type),
foreign key (application_ID) references applicant(application_ID)
on delete cascade,
foreign key (std_ID) references student(std_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table refer created successfully\n";
#Apply table
$sql="create table apply
(application_ID varchar(20),
sch_ID varchar(10),
distanceToSchl numeric(5,2),
academic_staff_ref varchar(30),
state_emp_ref varchar(30),
primary key (application_ID,sch_ID),
foreign key (application_ID) references applicant(application_ID)
on delete cascade,
foreign key (sch_ID) references school(sch_ID)
on delete cascade,
check (distanceToSchl > 0)
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table apply created successfully\n";
#attend table
$sql="create table attend
(std_ID varchar(20),
sch_ID varchar(10),
dateOfAdmission date not null,
dateOfLeave date,
state varchar(50),
primary key (std_ID,sch_ID),
foreign key (std_ID) references student(std_ID)
on delete cascade,
foreign key (sch_ID) references school(sch_ID)
on delete cascade,
check (state in ('current','past'))
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table attend created successfully\n";
# User table
$sql="Create table users
(u_ID varchar(20),
user_type varchar(20),
first_name varchar(100) not null,
last_name varchar(100) ,
street_no varchar(20),
streat_name varchar(100),
city varchar(100),
user_status varchar(20),
primary key(u_ID),
check (user_type in ('principal','interviewer','inserter','admin','clerk'))
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table users created successfully\n";
#school staff table
$sql="create table school_staff
(u_ID varchar(20),
sch_ID varchar(10),
user_type varchar(20),
foreign key (u_ID) references users(u_ID)
on delete cascade,
foreign key (sch_ID) references school(sch_ID)
on delete cascade,
check (user_type in ('principal','inserter','interviewer'))
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table school_staff created successfully\n";
# Login table
$sql="Create table login
(username varchar(100),
pwd varchar(250) not null,
u_ID varchar(20),
primary key(username),
foreign key (u_ID) references users(u_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table login created successfully\n";
# Interview Results Table
$sql="create table interview_result
(application_ID varchar(20),
u_ID varchar(20),
distance_mark numeric(5,2) check(distance_mark>=0.00 and distance_mark<=60.00),
parental_ref_mark numeric(5,2) check(parental_ref_mark>=0.00 and parental_ref_mark<=60.00),
sibling_ref_mark numeric(5,2) check(sibling_ref_mark>=0.00 and sibling_ref_mark<=60.00),
academic_ref_mark numeric(5,2) check(academic_ref_mark>=0.00 and academic_ref_mark<=60.00),
state_emp_mark numeric(5,2) check(state_emp_mark>=0.00 and state_emp_mark<=60.00),
total_mark numeric(5,2) check(total_mark>=0.00 and total_mark<=60.00),
primary key (application_ID,u_ID),
foreign key (application_ID) references applicant(application_ID)
on delete cascade,
foreign key (u_ID) references users(u_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table interview_result created successfully\n";
$sql="Create table activity
(u_ID varchar(20),
activity_ID int AUTO_INCREMENT,
avtivity varchar(255),
time_of_activity TIMESTAMP,
primary key(activity_ID),
foreign key (u_ID) references users(u_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table activity created successfully\n";
#phone tables
$sql="create table studentPhone
(std_ID varchar(20),
phone_number varchar(50),
primary key(std_ID,phone_number),
foreign key (std_ID) references student(std_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table studentPhone created successfully\n";
$sql="create table schoolPhone
(sch_ID varchar(10),
phone_number varchar(50),
primary key(sch_ID,phone_number),
foreign key (sch_ID) references school(sch_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table schoolPhone created successfully\n";
$sql="create table userPhone
(u_ID varchar(20),
phone_number varchar(50),
primary key(u_ID,phone_number),
foreign key (u_ID) references users(u_ID)
on delete cascade
)";
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create table: ');
}
echo "Table userPhone created successfully\n";
// Create index to search through activity table using user_ID
$sql='ALTER TABLE activity ADD INDEX uID_index (u_ID)';
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create index: ');
}
echo "uID_index created successfully\n";
// Create index to search through attend table to select studets of a single school easily
$sql='ALTER TABLE attend ADD INDEX schID_index (sch_ID)';
$retval = mysqli_query( $connection, $sql );
if(! $retval ) {
die('Could not create index: ');
}
echo "sch_ID_index created successfully\n";
?>