I have to store the following information into a database, to be used by a .NET assembly. They are representing times that a certain color is active:
RED: 16:30 – 18:30 Mon to Fri Incl Bank Holidays
AMBER: 09:00 – 16:30 & 18:30 – 20:30 Mon to Fri incl Bank Holidays &
16:30 – 18:30 Sat & Sun
GREEN: 00:00 – 09:00 & 20:30 –
24:00 Mon to Fri incl Bank Holidays & 00:00 – 16:30 * 18:30 – 24:00
Sat & Sun
I’ve initially set off with a database schema like so:
Column Name ID Pk Null? Data Type Default Histogram Encryption
Alg SaltRED_WEEKDAY_START 14 Y NUMBER None
RED_WEEKDAY_END 15 Y NUMBER None
RED_WEEKEND_START 16 Y NUMBER None
RED_WEEKEND_END 17 Y NUMBER None
AMBER_WEEKDAY_START 18 Y NUMBER None
AMBER_WEEKDAY_END 19 Y NUMBER None
AMBER_WEEKEND_START 20 Y NUMBER None
AMBER_WEEKEND_END 21 Y NUMBER None
GREEN_WEEKDAY_START 22 Y NUMBER None
GREEN_WEEKDAY_END 23 Y NUMBER None
GREEN_WEEKEND_START 24 Y NUMBER None
GREEN_WEEKEND_END 25 Y NUMBER None
However a couple of problems with this:
- Doesn’t deal with bank holidays (at all)
- Only allows one period of time for each colour (for example green being split up on weekdays)
So what would be a better way to go about storing this kind of data?
Five Columns
(RED: 16:30 – 18:30 Mon to Fri Incl Bank Holidays) translates to
AMBER: 09:00 – 16:30 & 18:30 – 20:30 Mon to Fri incl Bank Holidays & 16:30 – 18:30 Sat & Sun translates to
And I’ll leave the third line as an exercise!
Feel free to normalise dates and colours if you really want to save on space. The Bank holiday question requires another table of bank holidays which you can join to in any query you use:
PSEUDO SQL