Question : How to store a set in a field and how to maintain it dyamically?


Hello,

How in MySQL can I store information as set? for instance, assume there is a block of options where user can pick few of them or all of them. Now, instead of storing true/false in a number of fields (data type:boolean) is there a method that would allow me to store a set of tures or falses in one field as a set?

example:

check_box  married
check_box  veteran
check_box  have driving license

now these options can be marked or left unmarked .... question is how can I store all the statuses in a field
as FLD_STATUS where its values can be  Y|N|Y ?

How can I keep this dyamic now? meaning if one or more options are added (to its table) how can I change the size of set in FLD_STATUS?

Thanks!



Answer : How to store a set in a field and how to maintain it dyamically?

I was also going to suggest bitflags as above. You can also check for combinations, such as which records contain married veterans (with or without drivers license)

SELECT * FROM Table WHERE Flags & (1 | 2) = (1 | 2)

or those records that are only married veterans without drivers licenses

SELECT * FROM Table WHERE Flags = (1 | 2)
Random Solutions  
 
programming4us programming4us