Database
ERD
an accounts table to store account data for users
a questions table to store questions
topics to group the questions by
a feedback table to store answers for any quizzes the user has taken.
ACCOUNTS TABLE
Attribute |
Purpose |
Data type & constraints |
|---|---|---|
ACC_ID |
Unique ID |
SERIAL PRIMARY KEY |
ACC_username |
Unique username |
VARCHAR(26) NOT NULL UNIQUE |
ACC_password |
Password, min length 8, requires 1 digit and 1 non-alphanumeric character for security |
VARCHAR(16) NOT NULL CHECK (length(ACC_password)>=8 AND ACC_password GLOB ‘[0-9]’ AND ACC_password GLOB ‘[^a-zA-Z0-9]’) |
ACC_exp |
Account experience level tracking (unused) |
INT NOT NULL CHECK(ACC_exp >= 0) |
FEEDBACK/QUIZ TABLE
Attribute |
Purpose |
Data type & constraints |
|---|---|---|
FEED_ID |
Identifier for feedback |
INT NOT NULL |
ACC_ID |
Identifier for account |
INT NOT NULL, REFERENCES ACCOUNTS (ACC_ID) |
QUE_ID |
Question number in quiz |
INT NOT NULL, REFERENCES QUESTIONS (QUE_ID) |
FEED_answer_status |
Answer correct/incorrect |
BOOLEAN NOT NULL CHECK (FEED_answer_status IN (0, 1)) |
FEED_user_answer_index |
Which answer the user selected |
INT NOT NULL CHECK (FEED_user_answer_index BETWEEN 0 AND 3) |
FEED_ID differentiates each quiz/feedback object
ACC_ID points to which user the feedback is for
QUE_ID refers to which question the entry regards
FEED_answer_status stores if the question was answered correctly.
FEED_user_answer_index stores which option the user chose, allowing us to show the user what they got right/wrong.
QUESTIONS TABLE
Attribute |
Purpose |
Data type & constraints |
|---|---|---|
QUE_ID |
Unique question ID |
SERIAL PRIMARY KEY |
TOP_ID |
Topic ID |
INT NOT NULL, REFERENCES TOPICS (TOP_ID) |
QUE_question |
Question text |
VARCHAR(120) NOT NULL |
QUE_ans_1 |
Answer 1 text |
VARCHAR(120) NOT NULL |
QUE_ans_2 |
Answer 2 text |
VARCHAR(120) NOT NULL |
QUE_ans_3 |
Answer 3 text |
VARCHAR(120) NOT NULL |
QUE_ans_4 |
Answer 4 text |
VARCHAR(120) NOT NULL |
QUE_ans_correct |
Correct answer index (0-3) |
INT NOT NULL CHECK (QUE_ans_correct BETWEEN 0 AND 3) |
TOPIC TABLE
Attribute |
Purpose |
Data type & constraints |
|---|---|---|
TOP_ID |
Unique topic ID |
SERIAL PRIMARY KEY |
TOP_name |
Topic name |
VARCHAR(30) NOT NULL UNIQUE |