I created 9 columns each which hold either a 0 or a 1 integer. They exist so that users can toggle certain things on and off. I'd like to get rid of these 9 columns and instead use only one column where i can hold 9 0's and 1's for the 9 things my users will toggle. So say i have 000000000 and my user decides to toggle the first function, how would an update query for table accounts and column toggletimers look like which would change the value to 100000000 and so on for the 9 numbers?
-
1You can use SET data typesplash58– splash582015-08-06 14:01:52 +00:00Commented Aug 6, 2015 at 14:01
-
check out the user comments here: dev.mysql.com/doc/refman/5.1/en/bit-functions.htmlPepi– Pepi2015-08-06 14:03:32 +00:00Commented Aug 6, 2015 at 14:03
Add a comment
|
1 Answer
- You normally should not merge multiple fields into one in database design (violation of "1NF")
- If you really want to, use the bitwise operations:
update accounts set toggletimers = toggletimers | (1 << (9-1)) where ...