Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store days of week in a database

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

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

like image 359
m4Nu Avatar asked Nov 28 '12 07:11

m4Nu


1 Answers

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.

For example(binary):

00000001 -Sunday

00000011 - Monday and Sunday

00000101 - Tuesday and Sunday

00000111 - Monday,Tuesday and Sunday

Here you can find details and examples:

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

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

like image 102
valex Avatar answered Oct 23 '22 08:10

valex