r/SQL • u/imitationgamer • Jun 19 '19
PostgreSQL Store student timetables in PostgreSQL
For a project I'm working on, I need to store the course timetables of the students in my college in a PostgreSQL database (this is not my decision).
Some Background:
- College has around 3000 students and due to the freedom in course selection, we might as well as assume each student might have a unique course list.
- We have names for certain slots (let's say for example, Weekdays 9AM-10AM is slot A). Most courses follow these slots, but others have custom timings with classes of variable lengths of time.
- While it is uncommon, some courses have two classes on the same day. By class, I mean a single continuous chunk of time a student has to be present in the classroom.
- I will also have to store the course's start and end dates.
My ideas:
A table for the schedule of all courses and tables listing courses for each student.
- One hack for storing the course schedule for a week was to split it into half an hour intervals and store a string with binary values of whether a class is there in that period.
- Another way of storing the course schedule was to have a Day Start Time and Day End Time for each day. To work around have multiple classes on the same day, have Day Start Time 1, etc.
I see both the methods as hacky and was hoping someone could suggest a schema (or give me hints/resources to learn making one my own). It would be really nice if it used the built-in types in the database instead of parsing through strings.
I'm new to working with a SQL database and relatively new to Development, so my apologies if I have missed anything. I'm also not sure if a support request such as this is allowed here, but I couldn't find anything describing a solution I can adapt elsewhere and do not know where else I can ask.
Thank you.
View all comments
Show parent comment
1
u/da_chicken Jun 20 '19
The add/drop period would just be an operating rule. The system doesn't need to know everything, necessarily. You would write reports that your staff would have to look at to determine the number of days or weeks they were enrolled in the class. You could certainly do it programmatically, but that would be an additional application feature.
I guess I'm not entirely sure what you mean by a timetable.
Okay, so here's roughly what the tables look like. I'm leaving some fields out because there's additional features and complexity that would just confuse things (e.g., the system can support multiple districts, summer school is handled differently, etc.).
(Warning: This is pseudocode based on SQL Server. I don't expect the syntax to work, particularly with foreign keys.)
So, let's say we have an COMP101 course called "Database Design". The class meetsin building 22 on MWR 9:00 to 10:30 in room 330, and there's a lab section from 16:00 to 18:30 every F in the same room. It's a first semester class. You say that semester are divided into three. We call the divisions marking periods. So marking periods M1, M2, and M3. Second semester would be M4, M5, and M6. The teacher for the lectures has an ID of 2129, and the TA for the lab has an ID of 5642. Let's say that the lab doesn't get a separate mark on your report card.
So, to represent our course:
The artifical section_key is determined automatically. You'll have to fetch it back by querying the primary key or output it as I've done. I'll use
@section_keyto indicate the placeholder.Now we create a session for each meeting time for the class:
Here I put 4 credits on the lecture and none on the lab. There's attendance taken on the lecture, but not the lab.
Now we can add the staff. Let's say we know the professor might go to the lab sometimes so we want him and the TA as teacher on the lab session:
And specify the marking periods the class will meet. The start and end dates of the marking periods are defined elsewhere, as are which marking periods belong to which semester, when marks are issued, etc. For a real system, there's a lot of supporting data that determines your configuration.
And specify the days that the classes will meet. Again, the days that are available to select are defined elsewhere.
There would be more tables for report card information, but I haven't got any more time today to fully explain that.