SQL Server: varbinary or int to store a bit mask?

后端 未结 4 1178
面向向阳花
面向向阳花 2021-02-20 06:45

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

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 07:47

    I usually agree with @hainstech's answer of using bit fields, because you can explicitly name each bit field to indicate what it should store. However I haven't seen a practical approach to doing bitmask comparisons with bit fields. With SQL Server's bitwise operators (&, |, etc...) it's easy to find out if a range of flags are set. A lot more work to do that with equality operators against a large number of bit fields.

提交回复
热议问题