| 1 | drop table administrator cascade;
|
|---|
| 2 | drop table attempt cascade;
|
|---|
| 3 | drop table badge cascade;
|
|---|
| 4 | drop table badge_is_awarded_to_quiztaker cascade;
|
|---|
| 5 | drop table category cascade;
|
|---|
| 6 | drop table choice cascade;
|
|---|
| 7 | drop table hint cascade;
|
|---|
| 8 | drop table medal cascade;
|
|---|
| 9 | drop table medal_is_awarded_to_quiztaker cascade;
|
|---|
| 10 | drop table moderator cascade;
|
|---|
| 11 | drop table question cascade;
|
|---|
| 12 | drop table question_is_part_of_quiz cascade;
|
|---|
| 13 | drop table quiz cascade;
|
|---|
| 14 | drop table quiz_is_part_of_tournament cascade;
|
|---|
| 15 | drop table quiz_is_part_of_tournamentphase cascade;
|
|---|
| 16 | drop table quiztaker cascade;
|
|---|
| 17 | drop table quiztaker_participates_in_tournament cascade;
|
|---|
| 18 | drop table quiztaker_participates_in_tournamentphase cascade;
|
|---|
| 19 | drop table result_table cascade;
|
|---|
| 20 | drop table selectedchoice cascade;
|
|---|
| 21 | drop table selectionquestion cascade;
|
|---|
| 22 | drop table subject cascade;
|
|---|
| 23 | drop table textquestion cascade;
|
|---|
| 24 | drop table tournament cascade;
|
|---|
| 25 | drop table tournamentorganizer cascade;
|
|---|
| 26 | drop table tournamentorganizer_hosts_tournament cascade;
|
|---|
| 27 | drop table tournamentphase cascade;
|
|---|
| 28 | drop table user_table cascade;
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | create table user_table(
|
|---|
| 32 | userID serial primary key,
|
|---|
| 33 | fullName varchar(100),
|
|---|
| 34 | username varchar(50) not null unique,
|
|---|
| 35 | password_attr varchar(50) not null
|
|---|
| 36 | );
|
|---|
| 37 |
|
|---|
| 38 | create table administrator(
|
|---|
| 39 | userID integer primary key,
|
|---|
| 40 |
|
|---|
| 41 | constraint userID_fk foreign key(userID)
|
|---|
| 42 | references user_table(userID)
|
|---|
| 43 | );
|
|---|
| 44 |
|
|---|
| 45 | create table moderator(
|
|---|
| 46 | userID integer primary key,
|
|---|
| 47 |
|
|---|
| 48 | constraint userID_fk foreign key(userID)
|
|---|
| 49 | references user_table(userID)
|
|---|
| 50 | );
|
|---|
| 51 |
|
|---|
| 52 | create table tournament(
|
|---|
| 53 | tournamentID serial primary key,
|
|---|
| 54 | tournamentName varchar(50) not null
|
|---|
| 55 | );
|
|---|
| 56 |
|
|---|
| 57 | create table tournamentPhase(
|
|---|
| 58 | tournamentPhaseID serial primary key,
|
|---|
| 59 | tournamentID integer not null,
|
|---|
| 60 | tournamentPhaseName varchar(50) not null,
|
|---|
| 61 |
|
|---|
| 62 | constraint tournamentID_fk foreign key (tournamentID)
|
|---|
| 63 | references tournament(tournamentID)
|
|---|
| 64 | );
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | create table quizTaker(
|
|---|
| 68 | userID integer primary key,
|
|---|
| 69 |
|
|---|
| 70 | constraint userID_fk foreign key(userID)
|
|---|
| 71 | references user_table(userID)
|
|---|
| 72 |
|
|---|
| 73 | );
|
|---|
| 74 |
|
|---|
| 75 | create table tournamentOrganizer(
|
|---|
| 76 | userID integer not null,
|
|---|
| 77 | tournamentOrganizerID serial not null unique,
|
|---|
| 78 |
|
|---|
| 79 | constraint userID_fk foreign key(userID)
|
|---|
| 80 | references moderator(userID),
|
|---|
| 81 |
|
|---|
| 82 | constraint tournamentOrganizer_pk primary key(tournamentOrganizerID, userID)
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | );
|
|---|
| 87 |
|
|---|
| 88 | create table subject(
|
|---|
| 89 | subjectID serial primary key,
|
|---|
| 90 | subjectName varchar(100) not null
|
|---|
| 91 |
|
|---|
| 92 | );
|
|---|
| 93 |
|
|---|
| 94 | create table category(
|
|---|
| 95 | categoryID serial primary key,
|
|---|
| 96 | subjectID integer not null,
|
|---|
| 97 | categoryName varchar(100) not null,
|
|---|
| 98 |
|
|---|
| 99 | constraint subjectID_fk foreign key(subjectID)
|
|---|
| 100 | references subject(subjectID)
|
|---|
| 101 |
|
|---|
| 102 | );
|
|---|
| 103 |
|
|---|
| 104 | create table quiz(
|
|---|
| 105 | quizID serial primary key,
|
|---|
| 106 | categoryID integer not null,
|
|---|
| 107 | quizName varchar(100) not null,
|
|---|
| 108 |
|
|---|
| 109 | constraint categoryID_fk foreign key(categoryID)
|
|---|
| 110 | references category(categoryID)
|
|---|
| 111 |
|
|---|
| 112 | );
|
|---|
| 113 |
|
|---|
| 114 | create table medal(
|
|---|
| 115 | medalID serial primary key,
|
|---|
| 116 | tournamentID integer not null,
|
|---|
| 117 | medalName varchar(50) not null,
|
|---|
| 118 | description varchar(500) not null,
|
|---|
| 119 |
|
|---|
| 120 | constraint tournamentID_fk foreign key(tournamentID)
|
|---|
| 121 | references tournament(tournamentID)
|
|---|
| 122 |
|
|---|
| 123 | );
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | create table question(
|
|---|
| 127 |
|
|---|
| 128 | questionID serial primary key,
|
|---|
| 129 | questionText varchar(500) not null
|
|---|
| 130 |
|
|---|
| 131 | );
|
|---|
| 132 |
|
|---|
| 133 | create table hint(
|
|---|
| 134 | hintID serial primary key,
|
|---|
| 135 | hintText varchar(500) not null,
|
|---|
| 136 | questionID integer not null,
|
|---|
| 137 |
|
|---|
| 138 | constraint questionID_fk foreign key(questionID)
|
|---|
| 139 | references question(questionID)
|
|---|
| 140 | );
|
|---|
| 141 |
|
|---|
| 142 | create table textQuestion(
|
|---|
| 143 | questionID integer primary key,
|
|---|
| 144 |
|
|---|
| 145 | constraint questionID_fk foreign key(questionID)
|
|---|
| 146 | references question(questionID)
|
|---|
| 147 | );
|
|---|
| 148 |
|
|---|
| 149 | create table selectionQuestion(
|
|---|
| 150 | questionID integer primary key,
|
|---|
| 151 |
|
|---|
| 152 | constraint questionID_fk foreign key(questionID)
|
|---|
| 153 | references question(questionID)
|
|---|
| 154 | );
|
|---|
| 155 |
|
|---|
| 156 | create table choice(
|
|---|
| 157 | choiceID serial primary key,
|
|---|
| 158 | questionID integer not null,
|
|---|
| 159 | isCorrect boolean not null,
|
|---|
| 160 | choiceText varchar(500) not null,
|
|---|
| 161 |
|
|---|
| 162 | constraint questionID_fk foreign key(questionID)
|
|---|
| 163 | references selectionQuestion(questionID)
|
|---|
| 164 | );
|
|---|
| 165 |
|
|---|
| 166 | create table attempt(
|
|---|
| 167 | attemptID serial primary key,
|
|---|
| 168 | userID integer not null,
|
|---|
| 169 | attemptDate Date not null,
|
|---|
| 170 | quizID integer not null,
|
|---|
| 171 |
|
|---|
| 172 | constraint userID_fk foreign key(userID)
|
|---|
| 173 | references quizTaker(userID),
|
|---|
| 174 |
|
|---|
| 175 | constraint quizID_fk foreign key(quizID)
|
|---|
| 176 | references quiz(quizID)
|
|---|
| 177 | );
|
|---|
| 178 |
|
|---|
| 179 | create table selectedChoice (
|
|---|
| 180 |
|
|---|
| 181 | selectedChoiceID serial not null,
|
|---|
| 182 |
|
|---|
| 183 | choiceID integer not null,
|
|---|
| 184 |
|
|---|
| 185 | attemptID integer not null,
|
|---|
| 186 |
|
|---|
| 187 | constraint choiceID_fk foreign key(choiceID)
|
|---|
| 188 | references choice(choiceID),
|
|---|
| 189 |
|
|---|
| 190 | constraint attemptID_fk foreign key(attemptID)
|
|---|
| 191 | references attempt(attemptID),
|
|---|
| 192 |
|
|---|
| 193 | constraint selectedChoice_pk primary key(selectedChoiceID, choiceID)
|
|---|
| 194 |
|
|---|
| 195 | );
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 | create table result_table(
|
|---|
| 199 | resultID serial primary key,
|
|---|
| 200 | attemptID integer not null,
|
|---|
| 201 | points integer not null,
|
|---|
| 202 |
|
|---|
| 203 | constraint attemptID_fk foreign key(attemptID)
|
|---|
| 204 | references attempt(attemptID)
|
|---|
| 205 | );
|
|---|
| 206 |
|
|---|
| 207 | create table badge(
|
|---|
| 208 | badgeID serial primary key,
|
|---|
| 209 | badgeName varchar(100) not null,
|
|---|
| 210 | description varchar(500) not null,
|
|---|
| 211 | resultID integer not null,
|
|---|
| 212 |
|
|---|
| 213 | constraint resultID_fk foreign key(resultID)
|
|---|
| 214 | references result_table(resultID)
|
|---|
| 215 | );
|
|---|
| 216 |
|
|---|
| 217 | create table quiz_is_part_of_tournament(
|
|---|
| 218 | quizID integer not null,
|
|---|
| 219 | tournamentID integer not null,
|
|---|
| 220 |
|
|---|
| 221 | constraint quizID_fk foreign key(quizID)
|
|---|
| 222 | references quiz(quizID),
|
|---|
| 223 |
|
|---|
| 224 | constraint tournamentID_fk foreign key(tournamentID)
|
|---|
| 225 | references tournament(tournamentID),
|
|---|
| 226 |
|
|---|
| 227 | constraint pom1_pk primary key(quizID, tournamentID)
|
|---|
| 228 | );
|
|---|
| 229 |
|
|---|
| 230 | create table quiz_is_part_of_tournamentPhase(
|
|---|
| 231 | quizID integer not null,
|
|---|
| 232 | tournamentPhaseID integer not null,
|
|---|
| 233 |
|
|---|
| 234 | constraint quizID_fk foreign key(quizID)
|
|---|
| 235 | references quiz(quizID),
|
|---|
| 236 |
|
|---|
| 237 | constraint tournamentPhaseID_fk foreign key(tournamentPhaseID)
|
|---|
| 238 | references tournamentPhase(tournamentPhaseID),
|
|---|
| 239 |
|
|---|
| 240 | constraint pom8_pk primary key(quizID, tournamentPhaseID)
|
|---|
| 241 | );
|
|---|
| 242 |
|
|---|
| 243 | create table tournamentOrganizer_hosts_tournament(
|
|---|
| 244 | userID integer not null,
|
|---|
| 245 | tournamentID integer not null,
|
|---|
| 246 |
|
|---|
| 247 | constraint tournamentOrganizerID_fk foreign key(userID)
|
|---|
| 248 | references tournamentOrganizer(tournamentorganizerid),
|
|---|
| 249 |
|
|---|
| 250 | constraint tournamentID_fk foreign key(tournamentID)
|
|---|
| 251 | references tournament(tournamentID),
|
|---|
| 252 |
|
|---|
| 253 | constraint pom2_pk primary key(userID, tournamentID)
|
|---|
| 254 | );
|
|---|
| 255 |
|
|---|
| 256 | create table question_is_part_of_quiz(
|
|---|
| 257 | questionID integer not null,
|
|---|
| 258 | quizID integer not null,
|
|---|
| 259 |
|
|---|
| 260 | constraint questionID_fk foreign key(questionID)
|
|---|
| 261 | references question(questionID),
|
|---|
| 262 |
|
|---|
| 263 | constraint quizID_fk foreign key(quizID)
|
|---|
| 264 | references quiz(quizID),
|
|---|
| 265 |
|
|---|
| 266 | constraint pom3_pk primary key(questionID, quizID)
|
|---|
| 267 | );
|
|---|
| 268 |
|
|---|
| 269 | create table quizTaker_participates_in_tournament(
|
|---|
| 270 | userID integer not null,
|
|---|
| 271 | tournamentID integer not null,
|
|---|
| 272 |
|
|---|
| 273 | constraint userID_fk foreign key(userID)
|
|---|
| 274 | references quizTaker(userID),
|
|---|
| 275 |
|
|---|
| 276 | constraint tournamentID_fk foreign key(tournamentID)
|
|---|
| 277 | references tournament(tournamentID),
|
|---|
| 278 |
|
|---|
| 279 | constraint pom4_pk primary key(userID, tournamentID)
|
|---|
| 280 |
|
|---|
| 281 | );
|
|---|
| 282 |
|
|---|
| 283 | create table quizTaker_participates_in_tournamentPhase(
|
|---|
| 284 | userID integer not null,
|
|---|
| 285 | tournamentPhaseID integer not null,
|
|---|
| 286 |
|
|---|
| 287 | constraint userID_fk foreign key(userID)
|
|---|
| 288 | references quizTaker(userID),
|
|---|
| 289 |
|
|---|
| 290 | constraint tournamentPhaseID_fk foreign key(tournamentPhaseID)
|
|---|
| 291 | references tournamentPhase(tournamentPhaseID),
|
|---|
| 292 |
|
|---|
| 293 | constraint pom5_pk primary key(userID, tournamentPhaseID)
|
|---|
| 294 |
|
|---|
| 295 | );
|
|---|
| 296 |
|
|---|
| 297 | create table medal_is_awarded_to_quizTaker(
|
|---|
| 298 | medalID integer not null,
|
|---|
| 299 | userID integer not null,
|
|---|
| 300 |
|
|---|
| 301 | constraint medalID_fk foreign key(medalID)
|
|---|
| 302 | references medal(medalID),
|
|---|
| 303 |
|
|---|
| 304 | constraint userID_fk foreign key(userID)
|
|---|
| 305 | references quizTaker(userID),
|
|---|
| 306 |
|
|---|
| 307 | constraint pom6_pk primary key(medalID, userID)
|
|---|
| 308 | );
|
|---|
| 309 |
|
|---|
| 310 | create table badge_is_awarded_to_quizTaker(
|
|---|
| 311 | badgeID integer not null,
|
|---|
| 312 | userID integer not null,
|
|---|
| 313 |
|
|---|
| 314 | constraint badgeID_fk foreign key(badgeID)
|
|---|
| 315 | references badge(badgeID),
|
|---|
| 316 |
|
|---|
| 317 | constraint userID_fk foreign key(userID)
|
|---|
| 318 | references quizTaker(userID),
|
|---|
| 319 |
|
|---|
| 320 | constraint pom7_pk primary key(badgeID, userID)
|
|---|
| 321 | );
|
|---|