In my database I manage timetables like this:
timetables table
id - int (primary key)
start_time - int (minutes)
end_time - int (minutes)
week_day - int (day number: 1 for Monday, 7 for Sunday)
the id field is foreign key in other tables
since if a timetable is repeated for all days of the week and I have to store 7 rows in timetables and each other table with the foreign key
what about instead storing the week_day fields as an int of up to 7 digits (1234567) and query it as a string:
... WHERE week_day LIKE '%3%' /*wednesday*/
are there any cons in doing this?
UPDATE
my intention is to change timetables table
from:
id shop_id start_time end_time week_day (int)
1 1 480 720 1 /*shop1 08:00 - 12:00 monday*/
2 1 480 720 2 /*shop1 08:00 - 12:00 tuesday*/
3 1 480 720 3 /*shop1 08:00 - 12:00 wednesday*/
4 1 900 1140 7 /*shop1 15:00 - 19:00 sunday*/
into:
id shop_id start_time end_time week_day (int)
1 1 480 720 123 /*shop1 08:00 - 12:00 monday,tuesday,wednesday*/
2 1 900 1140 7 /*shop1 15:00 - 19:00 sunday*/
example query:
SELECT * FROM timetables WHERE shop_id=1 AND week_day LIKE '%3%'
OTHER POSSIBLE SOLUTION
id shop_id start_time end_time monday tuesday wednesday thursday friday saturday sunday
1 1 480 720 1 1 1 NULL NULL NULL NULL /*shop1 08:00 - 12:00 monday,tuesday,wednesday*/
2 1 900 1140 NULL NULL NULL NULL NULL NULL 1 /*shop1 15:00 - 19:00 sunday*/