DATABASE MANAGEMENT SYSTEM
FINAL TEAM PROJECT
Name| Student ID
Conceptual Design:
Our database is designed for a school where students’ details are kept alongside their scores
according to a particular year
The table has exactly six (6) attributes as listed below:
Student_id
Student_name
club
date_of_birth
year_of_study
student_marks
The above attributes are used to store each student data logically.
The table also has a primary key which is the student_id.
How the system works:
Our system works on the concept that the data is first added leaving the student marks first, then
filling the mark later
We can remove a particular student by selecting the student_id.
We have also made a schema to riverage that by constructing an ERD (entity diagram) diagram.
Entity Diagram:
Students
PK Student_id
Student_name
Date_of_birth
Year_of_study
club
Student_marks
Design:
The next step is where now we will Create and add data into our designed table.
Our table will be names as students, where the records are kept.
Below is the code:
--code to create the table first
CREATE TABLE "students" ("student_id" INT NOT NULL,"student_name" VARCHAR (30)
NOT NULL,"date_of_birth" DATE NOT NULL,"year_of_study" YEAR NOT NULL,"club"
VARCHAR (30) NOT NULL,"student_marks" INT NOT NULL, PRIMARY KEY
(“student_id”));
--insert into table students query:
1. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("1", "James d", "2021-04-04", "1", "green",5);
--insert into students’ query:
2. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("2", "peter k", "2021-04-03", "1", "green",20);
--insert into student’s query:
3. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("3", "jane", "2021-04-03", "1", "green",5);
--insert into student’s query:
4. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("4", "joe", "2021-04-03", "1", "green",30);
--insert into student’s query:
5. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("5", "Kate", "2020-08-13", "1", "green",6);
--insert into student’s query:
6. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("6", "Dickson", "2021-04-04", "1", "yellow",30);
--insert into student’s query:
7. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("7", "Mary", "2021-04-03", "1", "green",56);
--insert into student’s query:
8. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("8", "john", "2021-04-03", "1", "red",89);
--insert into student’s query:
9. INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("9", "James", "2021-04-03", "1", "green",100);
--insert into student’s query:
10.INSERT INTO "students"
("student_id”,"student_name”,"date_of_birth”,"year_of_study”,"club”, student_marks")
VALUES ("10", "pk", "2020-08-13", "1", "green",78);
CREATE TRIGGER marks_change
BEFORE UPDATE on students
for each row
declare marks_change cc
begin
marks_change:=new.marks/95 *100;
dbms_output.put_line("OLD MARKS" || old.student_marks);
dbms_output.put_line ("CALCULATED MARKS" || new.student_marks);
end;
CREATE TRIGGER new_student
BEFORE INSERT on students
for each row
declare new_student ns
begin
dbms_output.put_line("NEW STUDENT REGISTERED" || new.student_name);
end;
CREATE TRIGGER remove_product
BEFORE DELETE on students
for each row
declare remove_student rs
begin
dbms_output.put_line("STUDENT REMOVED" || old.student_id);
end;
CREATE TRIGGER check_change
BEFORE UPDATE on students
for each row
declare student_change sc
begin
dbms_output.put_line("PREVIOUS STUDENT INFO" || old.student_name);
dbms_output.put_line("CURRENT STUDENT INFO" || new.student_name);
end;
USAGE
The following are queries to fetch the data above:
1. SELECT club, COUNT(student_names) AS TOTAL_STUDENTS FROM students where
club="green";
2. SELECT COUNT(student_names) AS TOTAL_STUDENTS_FROM_RED_CLUB FROM
students where club="red";
3. SELECT * FROM students where student_marks >20;
4. SELECT * FROM students where date_of_birth like "%" "2020" "%";
5. SELECT MAX(student_marks) AS Highest_Marks from students;
6. SELECT MIN(student_marks) AS Lowest_Mark FROM students;
7. SELECT * FROM students;
8. SELECT * FROM students ORDER BY date_of_birth ASC;
9. SELECT AVG(student_marks) AS Average_mark FROM students;
10. SELECT SUM(student_marks) AS Total_SCore FROM students;
Query Results:
(1).
+-------+----------------+
| club | TOTAL_STUDENTS |
+-------+----------------+
| green | 8|
+-------+----------------+
1 row in set (0.06 sec)
(2).
+------------------------------+
| TOTAL_STUDENTS_FROM_RED_CLUB |
+------------------------------+
| 1|
+------------------------------+
1 row in set (0.00 sec)
(3).
+------------+--------------+---------------+---------------+--------+---------------+
| student_id | student_name | date_of_birth | year_of_study | club | student_marks |
+------------+--------------+---------------+---------------+--------+---------------+
| 4 | joe | 2021-04-03 | 2001 | green | 30 |
| 6 | dickson | 2021-04-04 | 2001 | yellow | 30 |
| 7 | Mary | 2021-04-03 | 2001 | green | 56 |
| 8 | john | 2021-04-03 | 2001 | red | 89 |
| 9 | james | 2021-04-03 | 2001 | green | 100 |
| 10 | pk | 2020-08-13 | 2001 | green | 78 |
+------------+--------------+---------------+---------------+--------+---------------+
6 rows in set (0.00 sec)
(4).
+------------+--------------+---------------+---------------+-------+---------------+
| student_id | student_name | date_of_birth | year_of_study | club | student_marks |
+------------+--------------+---------------+---------------+-------+---------------+
| 5 | Kate | 2020-08-13 | 2001 | green | 6|
| 10 | pk | 2020-08-13 | 2001 | green | 78 |
+------------+--------------+---------------+---------------+-------+---------------+
2 rows in set, 1 warning (0.11 sec)
(5).
+---------------+
| Highest_Marks |
+---------------+
| 100 |
+---------------+
(6).
+-------------+
| Lowest_Mark |
+-------------+
| 5|
+-------------+
1 row in set (0.00 sec)
(7).
+------------+--------------+---------------+---------------+--------+---------------+
| student_id | student_name | date_of_birth | year_of_study | club | student_marks |
+------------+--------------+---------------+---------------+--------+---------------+
| 1 | james d | 2021-04-04 | 2001 | green | 5|
| 2 | peter k | 2021-04-03 | 2001 | green | 20 |
| 3 | jane | 2021-04-03 | 2001 | green | 5|
| 4 | joe | 2021-04-03 | 2001 | green | 30 |
| 5 | Kate | 2020-08-13 | 2001 | green | 6|
| 6 | dickson | 2021-04-04 | 2001 | yellow | 30 |
| 7 | Mary | 2021-04-03 | 2001 | green | 56 |
| 8 | john | 2021-04-03 | 2001 | red | 89 |
| 9 | james | 2021-04-03 | 2001 | green | 100 |
| 10 | pk | 2020-08-13 | 2001 | green | 78 |
+------------+--------------+---------------+---------------+--------+---------------+
10 rows in set (0.00 sec)
(8).
+------------+--------------+---------------+---------------+--------+---------------+
| student_id | student_name | date_of_birth | year_of_study | club | student_marks |
+------------+--------------+---------------+---------------+--------+---------------+
| 10 | pk | 2020-08-13 | 2001 | green | 78 |
| 5 | Kate | 2020-08-13 | 2001 | green | 6|
| 2 | peter k | 2021-04-03 | 2001 | green | 20 |
| 3 | jane | 2021-04-03 | 2001 | green | 5|
| 4 | joe | 2021-04-03 | 2001 | green | 30 |
| 9 | james | 2021-04-03 | 2001 | green | 100 |
| 7 | Mary | 2021-04-03 | 2001 | green | 56 |
| 8 | john | 2021-04-03 | 2001 | red | 89 |
| 6 | dickson | 2021-04-04 | 2001 | yellow | 30 |
| 1 | james d | 2021-04-04 | 2001 | green | 5|
+------------+--------------+---------------+---------------+--------+---------------+
10 rows in set (0.02 sec)
(9).
+--------------+
| Average_mark |
+--------------+
| 41.9000 |
+--------------+
1 row in set (0.06 sec)
(10).
+-------------+
| Total_SCore |
+-------------+
| 419 |
+-------------+
1 row in set (0.00 sec)