By Cyrille C. Cervantes
Video overview: Student Records Database - CS50 SQL Project
The purpose of the database is to efficiently manage and store students records handled by teachers. This involves creating a robust SQL database capable of housing information such as student scores, grades and relevant data.
Essentially, the main goal of the project is to be able to replicate this sample table below where scores and grades of each student are properly managed by the sql database.
The database encompasses the following entities:
schools
which includes some basic information about the school;teachers
who handles the classes;students
attending a certain school and some of their basic information;sections
of each grade level in the school where students belong to;subjects
offered in the K-12 program and their components needed for computing student's grade;classes
offered in the school;assessments
given to each class; and- the individual
scores
of students on each respective assessments.
On the other hand, the database excludes:
- the
demographic
information of the students as only the necessary basic information are included.
This design streamlines the database, focusing specifically on the elements directly tied to class records and student performance, while having on mind the end-goal of providing a user-friendly interface for teachers.
This database will support
- CRUD operations for
schools
,teachers
,subjects
and itscomponents
,classes
,grade_sections
,students
, the schools they have attended, the classes they are enrolled in, theassessments
given to each classes, and thescores
of each student on each assessment.
The design of the database enable us to do the following:
- List all the students enrolled in a certain class;
- List all the classes taken by each student;
- List all the scores of the students; and lastly
- Compute for the grades of each student for each classes they are enrolled in.
Entities are captured in SQLite tables with the following schema.
Disclaimer: Most parts of this section were created by ChatGPT since this is a boring and tedious work. So, many thanks to ChatGPT! 😊.
schools
The schools
table includes:
id
, which specifies the unique ID for the school as anINTEGER
. This identifies the school hencePRIMARY KEY
constraint is applied.name
, which is the official name of the school inTEXT
form. Appropriate for name fields,TEXT
is used.region
, which specifies which region in the Philippines the school belongs to. The type is specified asTEXT
since there are regions that contain letters in it.division
, which states the division belongs to inTEXT
type.
teachers
The teachers
table includes the following.
id
, which specifies the unique ID for the teacher as anINTEGER
. This column thus has thePRIMARY KEY
constraint applied.first_name
, which specifies the first name of the teacher asTEXT
. Appropriate for name fields,TEXT
is used.middle_initial
, which specifies the middle initial of the teacher asTEXT
. This field isNULLABLE
since not all people have middle initial.last_name
, which specifies the teachers's last name.TEXT
is used for the same reason asfirst_name
.'s last name.TEXT
is used for the same reason asfirst_name
.
Normally, this table could only contain one data assuming there is only one teacher who handles a certain class.
subjects
The subjects
table includes the following.
id
, which specifies the unique ID for the subject as anINTEGER
. This column thus has thePRIMARY KEY
constraint applied.name
, which is the official name of the subject inTEXT
form. Appropriate for name fields,TEXT
is used.level
which specifies the grade level of the subject inINTEGER
. For non grade school subject, this might correspond to the number in the course name.track
which distinguishes the track of the subject, be it belongs to one of the following: Academic; Technical-Vocational-Livelihood; or Sports and Arts. For grade school subjects this isNULLABLE
.
components
The table components
are where we store the components of a subject needed for grade computation. The table includes the following:
id
, which specifies the unique ID for the component as anINTEGER
. This column thus has thePRIMARY KEY
constraint applied.name
, which is the name of the component inTEXT
form. Appropriate for name fields,TEXT
is used.percentage
, which specifies the weight of the component in relation to the computation of grades. The data should be inREAL
type and should be less than or equal to 1.0.
subject_components
This table, subject_components
is where we store the relationship between the subject and its components.
subject_id
, which specifies the unique ID for the subject from thesubjects
table.component_id
, which specifies the unique ID for the subject from thecomponents
table.- The pair (
subject_id
,component_id
) is subjected toUNIQUE
constraint to avoid repeition of data.
classes
The classes
table includes the following.
id
, which specifies the unique ID for the class as anINTEGER
. This column thus has thePRIMARY KEY
constraint applied.name
, which stores the formatted name of the class inTEXT
form. Appropriate for name fields,TEXT
is used. The name should obey the following format:{subject} {grad_level} {section_name} A.Y. {year} {sem} Sem
subject_id
, which specifies the ID from thesubjects
table corresponding to the subject taught in the class.teacher_id
, which specifies the ID from thesubjects
table corresponding to the teacher that manages the class.school_id
, which specifies the ID from theschools
table corresponding to the school where the class is taught.year
, which is the academic year (the first number inINTEGER
) the class is taught.year
, which is the semester (inINTEGER
) the class is taught.
grade_sections
The grade_sections
table comprises the following fields:
id
: AnINTEGER
representing the unique identifier for each grade section. This field is marked asNOT NULL
and serves as thePRIMARY KEY
.grade
: AnINTEGER
indicating the academic grade associated with the section. This field is marked asNOT NULL
.name
: ATEXT
field holding the name of the grade section. This field is marked asNOT NULL
.school_id
: AnINTEGER
specifying the ID from the schools table corresponding to the school where the grade section is located. This field is optional.adviser
: ATEXT
field storing the name or identifier of the adviser for the grade section. This field is optional.year
: AnINTEGER
denoting the academic year associated with the grade section. Only the first year is stored.
students
The students
table is defined by the following fields:
id
: AnINTEGER
serving as the unique identifier for each student. This field is marked as thePRIMARY KEY
.first_name
: ATEXT
field representing the first name of the student. This field is marked asNOT NULL
.middle_name
: ATEXT
field for capturing the middle name of the student. This field is optional since not all students have middle name.last_name
: ATEXT
field holding the last name of the student. This field is marked as NOT NULL.birth_date
: ADATE
field indicating the birth date of the student. This field is optional.gender
: AnINTEGER
field representing the gender of the student.
students_schools
The students_schools
table records the schools that students have attended with the following fields. This table provides information about the schools each student has attended, including start and, if applicable, end dates of attendance.
id
: AnINTEGER
serving as the unique identifier for each record in the table. This field is marked as thePRIMARY KEY
.student_id
: AnINTEGER
indicating the unique ID of the student associated with the school attendance. This field is marked asNOT NULL
and is linked to the id field in thestudents
table through a foreign key constraint.school_id
: AnINTEGER
specifying the unique ID of the school attended by the student. This field is marked asNOT NULL
and is linked to the id field in theschools
table through a foreign key constraint.start_date
: ADATE
field indicating the start date when the student began attending the specified school. This field is marked as NOT NULL.end_date
: ADATE
field representing the optional end date when the student concluded attendance at the specified school.
students_sections
The students_sections
table documents the sections to which students are assigned, featuring the following fields:
id
: AnINTEGER
acting as the unique identifier for each record in the table. This field is marked as thePRIMARY KEY
.student_id
: AnINTEGER
indicating the unique ID of the student. This field is marked asNOT NULL
and is linked to the id field in thestudents
table through a foreign key constraint.section_id
: AnINTEGER
specifying the unique ID of the grade section to which the student is assigned. This field is marked asNOT NULL
and is linked to the id field in thegrade_sections
table through a foreign key constraint.
Unique Constraint:
- A
UNIQUE
constraint is applied to the combination ofstudent_id
andsection_id
fields, ensuring that each student is uniquely associated with a grade section.
This table captures the assignments of students to specific grade sections, preventing duplicate entries for the same student and section pair.
students_classes
The students_classes
table records the classes in which students are enrolled, featuring the following fields:
student_id
: AnINTEGER
indicating the unique ID of the student. This field is marked asNOT NULL
and is linked to the id field in thestudents
table through a foreign key constraint.class_id
: AnINTEGER
specifying the unique ID of the class in which the student is enrolled. This field is marked asNOT NULL
and is linked to the id field in theclasses
table through a foreign key constraint.
Unique Constraint:
- A
UNIQUE
constraint is applied to the combination ofstudent_id
andclass_id
fields, ensuring that each student is uniquely associated with a class.
assessments
The assessments
table documents assessments under certain components
with the following fields:
id
: AnINTEGER
serving as the unique identifier for each assessment. This field is marked as thePRIMARY KEY
.name
: ATEXT
field representing the name of the assessment.max_score
: AnINTEGER
field specifying the maximum achievable score for the assessment. This field is marked asNOT NULL
.subject_id
: AnINTEGER
indicating the ID from the subjects table corresponding to the subject under which the assessment falls. This field is optional.component_id
: AnINTEGER
specifying the ID from the components table corresponding to the component under which the assessment is categorized. This field is marked asNOT NULL
and is very much needed for the grade computaiton. It is linked to the id field in thecomponents
table through a foreign key constraint.quarter
: AnINTEGER
field denoting the quarter during which the assessment is conducted.
class_assessments
The class_assessments
table captures assessments that are given to a certain class:
id
: AnINTEGER
serving as the unique identifier for each record in the table. This field is marked as thePRIMARY KEY
.class_id
: AnINTEGER
specifying the unique ID of the class associated with the assessment. This field is marked asNOT NULL
and is linked to the id field in theclasses
table through a foreign key constraint.assessment_id
: AnINTEGER
indicating the unique ID of the assessment conducted within the class. This field is marked asNOT NULL
and is linked to the id field in theassessments
table through a foreign key constraint.date_given
: A DATE field representing the date on which the assessment was conducted.
Unique Constraint:
- A
UNIQUE
constraint is applied to the combination ofclass_id
andassessment_id
fields, ensuring that each class is uniquely associated with an assessment.
scores
The scores
table stores scores of each student on a certain assessment with the following fields:
id
: AnINTEGER
serving as the unique identifier for each score. This field is marked as thePRIMARY KEY
.student_id
: AnINTEGER
indicating the unique ID of the student for whom the score is recorded. This field is marked asNOT NUL
L and is linked to the id field in thestudents
table through a foreign key constraint.assessment_id
: An INTEGER indicating the unique ID of the assessment for which the score is recorded. This field is marked asNOT NULL
and is linked to the id field in theassessments
table through a foreign key constraint.value
: AREAL
field representing the score achieved by the student. This field has a default value of 0.0 in case the student fails to take the exam.
These tables collectively provide a comprehensive structure for managing information related to student enrollment in classes, assessments, and their respective scores.
The entity relationship diagram below illustrates the connections between the entities within the database.
As outlined by the diagram:
- A
school
manages no or multiplegrade_sections
, has no or manystudents
and offers no or manyclasses
. - A
teacher
can teach manyclasses
but aclass
should only have oneteacher
. students
could be admitted to many schools as long as there is time conflict. He/she belongs to a certaingrade_section
managed by its current school, is enrolled to one or manyclasses
(needs to be enrolled to at least one class to be called a student).- A
class
is taught by ateacher
in aschool
with asubject
and should have at least onestudent
. A class could give 0 to manyassessments
(zero assessments may mean the class has yet to give an assessment). - A
subject
should at least have onecomponent
that is need for the grade computation. All the weights of the components should add up to 1.0. - To record the
scores
of the students, astudent
could take manyassessments
of different kind however, onescore
of that assessment is only given to the student.
The use-case of the database is assumed to use "id" as way to search for entities. Hence, there is no need to create indices for other columns. Since, ids as primary keys are automatically created for us by sqlite, I opted to not create indices anymore.
In addition, the database is assumed to be small, basing on the generalization that teachers usually handle 4-6 classes, hence, any optimizations could be insignificant.
With the current schema, sqlite alone cannot produce in one table the more detailed computation of the grades as there are dynamic numbers of quizzes as well as number of subject components. One work-around could be to use scripting program to overcome this problem.