-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.txt
More file actions
108 lines (98 loc) · 3.8 KB
/
data.txt
File metadata and controls
108 lines (98 loc) · 3.8 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
CREATE DATABASE certifywell;
USE certifywell;
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('student', 'examiner', 'admin') NOT NULL,
status ENUM('active', 'banned') DEFAULT 'active',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- Table for storing courses
CREATE TABLE Courses (
course_id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
description TEXT
);
-- Table for storing subjects, linked to courses
CREATE TABLE Subjects (
subject_id INT PRIMARY KEY AUTO_INCREMENT,
course_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
FOREIGN KEY (course_id) REFERENCES Courses(course_id) ON DELETE CASCADE
);
-- Table for storing exam details
CREATE TABLE Exams (
exam_id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
description TEXT,
subject_id INT NOT NULL,
created_by INT NOT NULL, -- User ID of the examiner/admin
total_marks INT NOT NULL,
time_limit INT NOT NULL, -- in minutes
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (subject_id) REFERENCES Subjects(subject_id) ON DELETE CASCADE,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Main table for storing all questions
CREATE TABLE Questions (
question_id INT PRIMARY KEY AUTO_INCREMENT,
subject_id INT NOT NULL,
question_text TEXT NOT NULL,
question_type ENUM('mcq', 'true_false', 'subjective', 'fill_blank') NOT NULL,
marks INT NOT NULL,
FOREIGN KEY (subject_id) REFERENCES Subjects(subject_id) ON DELETE CASCADE
);
-- Table for storing answer options for questions
CREATE TABLE Question_Options (
option_id INT PRIMARY KEY AUTO_INCREMENT,
question_id INT NOT NULL,
option_text TEXT NOT NULL,
is_correct BOOLEAN DEFAULT FALSE,
FOREIGN KEY (question_id) REFERENCES Questions(question_id) ON DELETE CASCADE
);
-- Linking table to associate questions with specific exams
CREATE TABLE Exam_Question_Bank (
exam_id INT NOT NULL,
question_id INT NOT NULL,
PRIMARY KEY (exam_id, question_id),
FOREIGN KEY (exam_id) REFERENCES Exams(exam_id) ON DELETE CASCADE,
FOREIGN KEY (question_id) REFERENCES Questions(question_id) ON DELETE CASCADE
);
-- Table to track each student's attempt at an exam
CREATE TABLE Student_Exam_Attempts (
attempt_id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT NOT NULL,
exam_id INT NOT NULL,
start_time DATETIME DEFAULT CURRENT_TIMESTAMP,
end_time DATETIME,
score DECIMAL(5,2),
status ENUM('started', 'submitted', 'graded') NOT NULL,
token VARCHAR(255) NOT NULL UNIQUE,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (exam_id) REFERENCES Exams(exam_id) ON DELETE CASCADE
);
-- Table to store the student's specific answers for each question
CREATE TABLE Answers (
answer_id INT PRIMARY KEY AUTO_INCREMENT,
attempt_id INT NOT NULL,
question_id INT NOT NULL,
answer_text TEXT,
option_id INT, -- chosen option if MCQ/True-False
is_correct BOOLEAN,
marks_awarded DECIMAL(5,2),
FOREIGN KEY (attempt_id) REFERENCES Student_Exam_Attempts(attempt_id) ON DELETE CASCADE,
FOREIGN KEY (question_id) REFERENCES Questions(question_id) ON DELETE CASCADE,
FOREIGN KEY (option_id) REFERENCES Question_Options(option_id) ON DELETE SET NULL
);
-- Table to store generated tokens for exam access
CREATE TABLE Generated_Tokens (
token_id INT PRIMARY KEY AUTO_INCREMENT,
exam_id INT NOT NULL,
student_id INT NOT NULL,
token VARCHAR(255) NOT NULL,
generated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (exam_id) REFERENCES Exams(exam_id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE
);