Is there any advantage of using int vs varbinary for storing bit masks in terms of performance or flexibility.
For my purposes, I will always be doing reads on these bit masks (no writes or updates).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should definitely use an
INT(if you need 32 flags) orBIGINT(for 64 flags). If you need more flags you could useBINARY(but you should probably also ask yourself why you need so many flags in your application).Besides, if you use an integral type, you can use standard bitwise operators directly without converting a byte array to an integral type.
If you do need more flags and have to use
BINARYyou lose native support for bitwise operators and therefore easy support for checking flag values. I would probably move checking for flag values to a client application but if you’re comfortable programming in T-SQL that’s an option as well. If you’re using C# you have aBitArrayclass with the necessary operations and in Java you have aBitSetclass.