I am currently trying to prepare the best way to store a business's operating hours in the database.
For example:
Business A has the following hours of operation
- Monday: 9am - 5pm
- Tuesday: 9am - 5pm
- Wednesday: 9am - 5pm
- Thursday: 9am - 5pm
- Friday: 9am - 5pm
- Saturday: 9am -
- < Li>
- No primary null primary key, "day" varchar (16) no, zero, "open_time" time, "close_time" time)
where The "day" is restricted to the choice of 7 days in the code (through ORM) check it Area is for a business to be closed on a particular day, it checks whether it is related to the business through open_time and close_time tap is an intermediate table (too many relationships).
Is there any suggestion for this database scheme? Nothing about it seems right to me
Overall, I do not see anything wrong with this. Except ...
-
I will store the day of week as an integer using whatever number system (in my libraries) that uses my original programming language. Reduce the size of the database and remove the comparison of the string from your code.
-
Maybe I will put foreign keys directly into the business table in this table. In this way you will not need a link table.
So what I will do is:
create table "business_hours" ("id" integer no primary key, "business_id "My business argument in foreign foreign key reference" business "," day "integer zero," open_time "time," close "time) I apply a barrier Each "business" has at least 7 "business hours" ( at least because John Skeet is right, you may be Each light hours.) However, you can trade off for the day to just leave "business hours" to relax this constraint.
Comments
Post a Comment