Uploaded by Omar alrbaey

Assignment#2 -

advertisement
The Libyan Academy (Zintan Branch)
School of Engineering and Applied Sciences
Department of Electrical Engineering and Computing
Information Technology Pathway
Module: Database Technology (ITE645)
Assignment#2
Implementation of Online Test System
Database
By:
Amira Abdullah Al-Majdam
Fatema Melad Shalouf Tahani Essa Alconsul Yasmeen mohy aldeen altuwati -
Fall 2022 – 2023
 Database Name: online_test_system
 Database table structure
-
Tables of Database
No
1.
2.
3.
4.
5.
6.
7.
Table Name
group
group_has_student
group_has_test
option
question
result
student
8.
student_choose_option
9.
student_phone
10.
student_take_test
11.
12.
13.
teacher
teacher_has_advisor
teacher_phone
14.
teacher_qualification
15.
16.
test
test_grade
17.
test_has_question
Description
Contains group data
Table of the relationship between the group and the student
Table of the relationship between the group and the test
Contains question options (correct and incorrect answers)
Contains question data
Contains the results of the students in the tests for easy access
Contains student data
Table of the relationship between the student and the options he
chose
contains students' phone numbers
Table of the relationship between the student and the tests that he
took
Contains teacher data
contains the data of the teacher and the advisor teacher
contains teachers' phone numbers
contains information about the educational qualification of the
teacher
Contain tests data
Contains test scores determined by the teacher
Table of the relationship between the test and the questions that
make it up
1
 Structure of teacher table
2
 Structure of teacher_phone table
 Structure of teacher_qualification table
 Structure of teacher_has_advisor table
 Structure of student_phone table
3
 Structure of student table
 Structure of group table
 Structure of group_has_student table
4
 Structure of test table
 Structure of test_grade table
 Structure of group_has_test table
5
 Structure of student_take_test table
 Structure of question table
 Structure of test_has_question table
 Structure of option table
6
 Structure of student_choose_option table
 Structure of result table
 Add some data to the tables
 Add teacher
INSERT INTO `teacher` (`ID`, `teacher_FirstName`, `teacher_ScondName`,
`teacher_LastName`, `teacher_Email`, `teacher_Password`, `teacher_BirthDate`,
`teacher_Gender`)
VALUES ('1', 'Youssef', 'Ahmed', 'Abu Sitta', 'youssef@gmail.com', '0000',
'1980-01-10', 'male');
 Add group
INSERT INTO `group` (`ID`, `group_Name`, `group_CreateDate`, `teacher_Id`)
VALUES ('1', 'database1', '2023-01-16', '1'), ('2', 'Java', '2023-01-16', '1');
7
 Add student
INSERT INTO `student` (`ID`, `student_FirstName`, `student_SecondName`,
`student_LastName`, `student_Email`, `student_Passsword`, `student_BirthDate`,
`student_Gender`) VALUES ('1', 'hassan', 'essa', 'cl', 'tahani@yahoo.com',
'0000', '1993-8-22', 'female'), ('2', 'salem', 'ahmed', 'salem',
'salem@yahoo.com', '0000', '1994-1-1', 'male');
 Some Queries
 View all teachers' information
SELECT DISTINCT t.*, tp.country_Code, tp.phone_Number , tq.degree,
tq.specialization
FROM `teacher` as t, `teacher_qualification` as tq, `teacher_phone` as tp
WHERE tp.teacher_Id = t.ID AND tq.teacher_Id= t.ID AND t.ID = t.ID;
 View group information
SELECT DISTINCT g.ID, g.group_Name, g.group_CreateDate, t.teacher_FirstName, t.t
eacher_LastName, COUNT(gs.student_Id) AS count_of_students
FROM `group` AS g, `teacher` AS t, `group_has_student` AS gs
WHERE gs.group_Id = g.ID AND g.teacher_Id = t.ID AND g.ID = g.ID GROUP BY g.grou
p_Name;
8
 View student information in ascending order by first name
SELECT s.*, sp.country_Code, sp.phone_Number , COUNT(gs.group_Id) AS
groups_joined
FROM `student` as s, student_phone AS sp, group_has_student AS gs
WHERE sp.student_Id = s.ID AND gs.student_Id = s.ID
GROUP BY s.student_FirstName ASC;
 View the tests that are being conducted today
SELECT ts.ID, ts.test_Name, ts.test_StartTime, ts.test_EndTime,
ts.test_PeriodTime, ts.test_Date, ts.create_Date, t.teacher_FirstName
FROM `test` AS ts, `teacher` AS t
WHERE ts.teacher_Id = t.ID AND ts.test_Date = CURRENT_DATE();
 View a complete test (questions, correct and wrong answers as True or False, and the score for each
question) for the “database midterm” test created by the teacher “Youssef Abu Sitta”, with a display
of the serial number of the questions
SELECT @rownum:=@rownum+1 AS No, q.question_content, q.question_grade,
o.option_content,
CASE
WHEN o.option_Type = 0 then 'False'
9
WHEN o.option_Type = 1 then 'True'
END as option_Type
FROM question as q , `option` as o , teacher as tr , test as t ,
test_has_question as tq , (SELECT @rownum:=0) r
WHERE q.ID = o.question_Id AND t.ID = tq.test_Id AND q.ID = tq.question_Id AND
tr.ID = t.teacher_Id AND t.test_Name = "Database Midterm" AND
tr.teacher_FirstName = "Youssef" AND tr.teacher_LastName = "Abu Sitta";
 Display questions and score for each question and correct answers only to each question for the test
database midterm created by Professor Youssef Abu Sitta
SELECT @rownum:=@rownum+1 AS No, q.question_content, q.question_grade ,
o.option_content
FROM question as q , `option` as o , teacher as tr , test as t ,
test_has_question as tq , (SELECT @rownum:=0) r
10
WHERE q.ID = o.question_Id AND t.ID = tq.test_Id AND q.ID = tq.question_Id AND
tr.ID = t.teacher_Id
AND t.test_Name = "Database Midterm" AND tr.teacher_FirstName = "Youssef" AND
tr.teacher_LastName = "Abu Sitta" AND o.option_Type = 1 ;
 Displays the names of students who have taken the “Database Midterm” Test
SELECT s.student_FirstName, s.student_SecondName, s.student_LastName
FROM student as s, test as t ,student_take_test as st
WHERE s.ID =st.student_Id AND t.ID = st.test_Id AND t.test_Name = "Database
Midterm";
 Display the students` scores with the full name, the final score of the test, and the result (passed or
failed)
SELECT @rownum:=@rownum+1 AS No, s.student_FirstName, s.student_SecondName,
s.student_LastName, SUM(q.question_grade) AS Score , tg.full_grade ,
CASE
WHEN SUM(q.question_grade) < tg.passing_grade then 'fail'
11
WHEN SUM(q.question_grade) >= tg.passing_grade then 'successful'
END as result
FROM question as q, student_choose_option as so, `option` as o, student as s,
test_grade as tg, test as t, (SELECT @rownum:=0) r
WHERE s.ID = so.student_Id AND q.ID = o.question_Id AND o.ID = so.option_Id AND
tg.test_Id = t.ID
AND so.option_Id IN ( SELECT so.option_ID
FROM student_choose_option as so, `option` as o
WHERE so.option_Id=o.ID AND o.option_Type=1
AND so.student_Id IN (SELECT s.ID
FROM student as s , test as t ,student_take_test as st
WHERE s.ID =st.student_Id AND t.ID = st.test_Id
AND t.test_Name = "Database Midterm"))
GROUP BY s.student_FirstName;
Thank You …
12
Download