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
In our system, there's two ways to handle classes that have multiple meeting times.
The first is to just create two classes and schedule students into both. This might be useful if, for example, CHEM101-1 is a huge auditorium lecture class with 300 students, and the CHEM101L-1 through CHEM101L-12 are the breakout labs and review sections, but there's different sections throughout the week so no more than 26 students are in a section.
The system itself can handle one class with multiple different meeting times, too. It does this like so:
There's the base master schedule table. One record for every section of a course. This has the overall course information, including the information copied from the catalog, as well as the identifier for the individual section.
Each section has one or more sessions, which are a separate table. Each session has it's own description. Each session has a start and end period (or time), a semester (or marking period) when that session meets, the room it's in, the credit for that session, the days of the week the course meets, whether or not attendance is taken by the teacher, and so on. The staff information table links to this table, too, as well as the grade configuration (what report card marks are issued). When a student is scheduled into one section, they're scheduled into all sessions of the class.
It does have some issues. Report card marks issued on report cards by course section, not by session, so essentially only one session in a section can be configured to have marks. That's fine if you have a class that legitimately meets at different times, but the lecture and review example above doesn't work well here because (at least when I took Chemistry) the lab and the lecture both had their own grade and credit.
Performance can be an issue, but for the most part it won't be. If you have an even remotely reasonable amount of RAM in your SQL Server, the queries will work just fine. The vast majority of the time, you're getting data about one class or one student for one year. That filters out the lion's share of the records. Yes, if you want to generate all schedules for all active students with all relevant child tables it might take awhile, but you're only going to do that once or twice a year.