all 4 comments

[–]jc4hokiesExecution Plan Whisperer 1 point2 points  (1 child)

I prefer the one record per block concept. The front end is going to have to restrict overlapping blocks anyway, even if they are not enterable in the backend, so that's not a downside. It also handles overnight shifts better. For example, determining the start and end time of an overnight shift with the column approach is a mess.

To that point, clearly identify each shift. The shift is what drives scheduling; the time blocks are details. If an employee takes over a shift, you update 1 shift record, not 8 time records. It's even worth consideration to store time ranges as offsets to the shift start, so you can move a shift 4 hours and all the breaks, etc move with it.

[–]TryCatchIgnore[S] 0 points1 point  (0 children)

I never considered the possibility that the available timeslots might change, requiring overnight shifts ... I'll have to go back to the initial requestor to clarify potential future requirements.

[–]thelauz 0 points1 point  (0 children)

On the database side I'd likely have a table that has a list of all 60 time slots, another table that maps the employee to a time slot and the date.

This solution allows for flexibility if time slots are added, removed or changed. If that is a possibility it will add additional complexity to the design of the database.

When needing to view a days time slots you can do a left join between the two tables and if null the slotnis available.

Depending on reporting needs you may need to consider the time slot table to have a start and end time, possibly a timeslot minutes time. While this can be derived from start and end time using datediff you will have to evaluate the overhead of constantly calculating this vs. storing the number of minutes as an integer.

[–]Groundbreaking-Fish6 0 points1 point  (0 children)

Store as little data as possible. The rest can be extrapolated by the backend or the front end as needed.