如何在数据库中存储工作日 [英] How to store opening weekdays in a database
问题描述
我有一组复选框,用户可以在其中选择某些工作日(商店的营业日).如何保存选定的日期?我应该在同一字段中保存类似于0111111(零表示星期日不开放)的内容,并在读取数据时拆分结果吗?还是每天创建一个字段,然后在每个(奇怪的)位置存储0或1?
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? Should 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屋!