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

in utopian-io •  6 years ago 

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.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thank you for your contribution.
After review your contribution we recommend the following:

  • The utopian tutorials are specifically to be used in a technical way to help the open source community learn new content.

  • In the next tutorial we suggest you use the tutorials template. Link

  • Check this tutorial Link, is a good example of a tutorial.

Please read the guidelines here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @portugalcoin!

So far this week you've reviewed 3 contributions. Keep up the good work!