user3544582
user3544582

Reputation: 17

MYSQL update the only x'th number in integer/bit datatype field

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?

Upvotes: 1

Views: 54

Answers (1)

JimmyB
JimmyB

Reputation: 12610

  1. You normally should not merge multiple fields into one in database design (violation of "1NF")
  2. If you really want to, use the bitwise operations: update accounts set toggletimers = toggletimers | (1 << (9-1)) where ...

Upvotes: 1

Related Questions