SQL design approach for searching a table with an unlimited number of bit fields

前端 未结 5 2168
失恋的感觉
失恋的感觉 2020-12-31 23:01

Consider searching a table that contains Apartment Rental Information: A client using the interface selects a number of criteria that are represented as bit fields in the D

5条回答
  •  攒了一身酷
    2020-12-31 23:51

    I've never tested this, but what if you were to create a varchar(256) fields that stored all of your flags as one long string of 0's and 1's.

    For example,

    • AllowsPets = 1
    • HasParking = 0
    • HasDeck = 1
    • ModernKitchen = 1

    would be:

    • PropertyFlags = 1011

    and if you were looking for something that AllowsPets and HasDeck, then the search query would look something like this:

    WHERE PropertyFlags LIKE '1_1_' (the underscore represents a single wildcard character in the like clause)

    this would solve your issues with adding additional columns to the search in the future, but I'm not sure how this would do performance-wise.

    has anyone out there tried anything similar to this?

提交回复
热议问题