开发者

How to store opening weekdays in a database

开发者 https://www.devze.com 2022-12-28 17:16 出处:网络
I have a group of checkboxeswhere the user selects some of the weekdays (the opening days of a store). How can I save the selected days? 开发者_如何学JAVAShould I save something like 0111111 (zero mea

I have a group of checkboxes where the user selects some of the weekdays (the opening days of a store). How can I save the selected days? 开发者_如何学JAVAShould I save something like 0111111 (zero means closed on sunday) on the same field and split the result when reading the data? Or create a field for each day and store 0 or 1 on each (weird)?


The first approach saves space, the second improves performance while retrieving data, especially if you need to filter by individual weekday. It also makes the queries that manipulate weekdays a way clearer. You have to decide what is more important to you based on the application's logic.

In general, I'd use field-per-day solution.


It totally depends on what you are going to do with that data once you have it. By and large, if these seven factoids (weekdays that the store is opn) are one fact, will be treated as one fact, and you'll never need to parse out and individually process one of the "factoids" within the string, then it can and possibly should be stored as one piece of data.

But, if you'll have to consider this infomation as seven distinct pieces of data, you'll be better off recording it as seven different pieces of data (i.e. seven different columns).

Again, there's a whole lot of "it depends" behind this. Another way to think of it is, look ahead to how you will be using the data, and try and structure your storage to simplify your processes (i.e. do you want to always be parsing string "1010101" for the element(s) you want?)

0

精彩评论

暂无评论...
验证码 换一张
取 消