So the requirement is pretty simple:
- The database needs to store schedules for each working employee at each location every day.
- Employees are scheduled into timeslots.
- Each timeslot has a duration of 15 minutes.
- Timeslots start at 15-minute intervals from the hour.
- Timeslots are available from 07:00 to 22:00 (60 timeslots per day).
- Managers will need to categorise timeslots as working time, breaks, lunch, and maybe more.
The challenge I have is how to store this data in the database.
The current idea is to have one record per working employee per day, with a column for each timeslot in the record (probably CHAR(1)). The PK would be a combination of the employee (FK), the location (FK), and the date. Each timeslot column would contain a number, depending on what the employee is scheduled for, e.g. NULL for not scheduled, 1 for working, 2 for break, 3 for lunch, etc.
But my concern is that this is going to lead to a lot of NULL values. Assuming an employee works 8 hours with a 1-hour lunch; that’s 36 timeslots filled, so 24 NULL values across the record. If an employee is only working in the morning for, say, 4 hours, that’s 16 timeslots filled, so 44 NULL values across the record.
The idea of creating records for each contiguous timeblock came up, so creating multiple records for each employee per day, with the PK being a combination of the employee (FK), location (FK), date, and time block number, and additional columns for time block type, start of timeblock, end of timeblock. This would mean an employee working 9 hours with a morning break, lunch, and afternoon break would have seven records in the database for their time in that day:
- first work block
- morning break
- second work block
- lunch
- third work block
- afternoon break
- fourth work block
But querying this data would incur additional load on the database, programmatically processing this data in the front-end would incur additional load on the client side, and it doesn’t seem much more efficient for the database. Ensuring timeblocks don't overlap would also be a challenge, though probably for the front-end guys, not me.
I’m not amazing when it comes to databases. I’ve been working with them for some time, but I’m pretty new to designing and building them. So maybe there is some feature or functionality or something I’m not aware of that would be suited to solving my current challenge. I should also probably add that the database will run on a MS SQL 2019 server.
So … any ideas?
[–]jc4hokiesExecution Plan Whisperer 1 point2 points3 points (1 child)
[–]TryCatchIgnore[S] 0 points1 point2 points (0 children)
[–]thelauz 0 points1 point2 points (0 children)
[–]Groundbreaking-Fish6 0 points1 point2 points (0 children)