将星期几存储在数据库中 [英] Store days of week in a database

查看:310
本文介绍了将星期几存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为学校做一个小项目.在数据库表中存储星期几的最佳可能性是什么?

I have to do a small project for school. What is the best possibility to store days of the week in a database table?

例如一周中的几天进行数据备份-我应该使用像这样的列:

E.g. days of the week for data backup — should I use a column like this:

backupDays varchar(50)
1,5       >> monday + friday
2,3,4     >>tuesday + wednesday + thursday

我必须在asp.net MVC程序中使用此表,并且使用MSSQL数据库.

I have to use this table in my asp.net MVC program and I use a MSSQL database.

推荐答案

在这种情况下(一个字段中有7个布尔值),我们得到了仅7位长的二进制集.因此,您可以在MS SQL中使用一种字节长度的字段类型- tinyint .并使用按位运算符对其进行操作.

In this case (7 boolean values in the one field) we get a binary set only 7 bits long. So you can use one byte length field type in MS SQL - tinyint. And use bitwise operators to manipulate it.

例如(二进制):

00000001-周日

00000001 -Sunday

00000011-星期一和星期日

00000011 - Monday and Sunday

00000101-周二和周日

00000101 - Tuesday and Sunday

00000111-周一,周二和周日

00000111 - Monday,Tuesday and Sunday

在这里您可以找到详细信息和示例:

Here you can find details and examples:

http://sqlfool.com/2009/02/bitwise-operations/

http://www. mssqltips.com/...

这篇关于将星期几存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆