Please do not use bitwise flag columns, as someone who works for a company that made this decision a while back.

Don't do this: https://www.mssqltips.com/sqlservertip/1218/sql-server-bitwise-operators-store-multiple-values-in-one-column/

When I started working at my current place of employment, I found that user permissions and material properties were being stored in bitwise columns.

For example: if your UserFlags column has 2563
Then the user has 4 of the available permissions.

This has been a pain-in-the-ass from day 1, because when any of that data changes, we now have to update all of the records with the new permission set.

The better solution is to use a many-to-many relationship table.

In the example in that link, you're much better off having a PhoneNumbers table with columns like

  • PersonID (foreign key to table you were going to store that bitwise column)
  • Home
  • HomeFax
  • Mobile
  • Office
  • OfficeFax

Then if you need to add a new number type like TollFreeOffice you'd just add a nullable column.

And, if you absolutely have to have your bitwise set for phone numbers, for whatever reason, returned in your code, simply create a view that does the bitwise gymnastics necessary in the above link.

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center