I need help on the best way to design a database/tables for the following data.
I have a supplier : Supplies various products for a Project.
For each product they supply. the rate changes depending on the day of the week, the time of day and if it is a public holiday or a weekend.
Any Ideas???
Example:
Week Day Rates | Saturday/Sunday & Public Holiday Rates
Start Time 0:00 3:00 6:00 17:00 | 0:00 3:00 6:00 17:00 20:00
End Time 3:00 6:00 17:00 20:00 | 3:00 6:00 17:00 20:00 23:59
Product 1 1.00 2.00 3.00 4.00 | 6.00 7.00 8.00 9.00 10.00
Product 2 5.00 8.00 8.00 9.00 | 2.00 6.00 7.00 8.00 9.00
Product 3 3.00 2.00 3.00 5.00 | 3.00 4.00 5.00 8.00 10.00
The best way to manage this while minimizing the amount of data to maintain and preserving flexibility is to use ranges of date/time. For the holiday rate, you can either keep two rate columns (regular/holiday) or you can keep separate records with a flag indicating whether the price is for a regular day or a holiday.
You have choices for how to represent this information. You could represent it using datetime columns adjusted to some arbitrary starting date. That would be simple in terms of columns, but it could be confusing to use. The other way to go would be to use two columns: Day_of_Week (tiny int) and Time (datetime without a date or time only, if your DBMS supports it).
I’d recommend the second option. So your table could look like this:
Of course, you’ll want to add in the primary and foreign key constraints…