-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_design.sql
132 lines (113 loc) · 2.87 KB
/
db_design.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
CREATE TABLE student (
_id INT PRIMARY KEY AUTO_INCREMENT,
fname VARCHAR(50) NOT NULL,
lname VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(50) NOT NULL,
year VARCHAR(50) NOT NULL,
department VARCHAR(50) NOT NULL
);
CREATE TABLE teacher (
_id INT PRIMARY KEY AUTO_INCREMENT,
fname VARCHAR(50) NOT NULL,
lname VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(50) NOT NULL,
);
-- course is same as classroom
CREATE TABLE course (
_id INT PRIMARY KEY AUTO_INCREMENT,
teacher_id INT NOT NULL,
name VARCHAR(50) NOT NULL,
description VARCHAR(200),
year VARCHAR(4) NOT NULL,
department VARCHAR(10) NOT NULL,
course_code VARCHAR(10) NOT NULL UNIQUE
);
-- used to check what courses is a student registered to
CREATE TABLE records(
student_id INT,
course_id INT,
PRIMARY KEY (student_id, course_id)
);
CREATE TABLE assignment (
_id INT PRIMARY KEY AUTO_INCREMENT,
course_id INT NOT NULL,
title VARCHAR(50),
description VARCHAR(200),
due_date DATE,
max_marks INT(3),
is_assignment BOOLEAN NOT NULL
);
CREATE TABLE submissions (
data BLOB NOT NULL,
assignment_id INT NOT NULL,
student_id INT NOT NULL,
marks_obtained INT(3) NOT NULL,
PRIMARY KEY (assignment_id, student_id)
)
CREATE TABLE attachments (
_id INT PRIMARY KEY AUTO_INCREMENT,
data BLOB NOT NULL,
assignment_id INT NOT NULL,
name VARCHAR(100) NOT NULL,
description VARCHAR(200),
)
CREATE TABLE notes (
_id INT AUTO_INCREMENT,
user_id INT,
day VARCHAR(50),
date VARCHAR(50),
time VARCHAR(50),
content VARCHAR(300),
PRIMARY KEY (_id, user_id)
);
CREATE TABLE quiz (
_id INT PRIMARY KEY AUTO_INCREMENT,
number_of_questions INT,
total_marks INT,
is_active BOOL,
teacher_id INT NOT NULL,
course_id INT NOT NULL,
quiz_title VARCHAR(200)
);
CREATE TABLE question (
question_id INT AUTO_INCREMENT,
quiz_id INT NOT NULL,
question_title VARCHAR(200),
question_type VARCHAR(10),
option_1 INT,
option_2 INT,
option_3 INT,
option_4 INT,
correct_option INT,
textual_ques_marks INT,
min_char INT,
QID INT NOT NULL,
PRIMARY KEY (question_id, quiz_id )
);
CREATE TABLE quiz_submission (
quiz_id INT NOT NULL,
student_id INT NOT NULL,
total_marks INT,
marks_obtained INT,
PRIMARY KEY (quiz_id, student_id)
)
**************STORED PROCEDURE******************
First create a table with cols
ass_id AVG MAX MIN Absentees
****EXXAMPLE****
delimiter //
CREATE PROCEDURE display_book()
-> BEGIN
-> SELECT * FROM book;
-> END //
call display_book(); //
***** sendReport*******
DELIMITER //
DROP PROCEDURE IF EXISTS send_report//
CREATE PROCEDURE send_report(IN ass_id integer)
BEGIN
SELECT AVG(marks), MAX(marks), MIN(marks), COUNT(marks) FROM submissions WHERE assignment_id=ass_id;
END//
DELIMITER ;