Column(s) type for too many boolean property

  • Hi all,

    if you had an object with too many boolean properties (checkboxes on forms)how would your column(s) type(s) to store its properties in your tables. i am using only a column with varchar type. A sample value of this column is 011100. only 0 and 1 is permitted and one of them shows one property is set or not. is there any better way i can use? Or What is the pros and cons of this method that i could not notice

    best regards,

    Erman OLCA

  • I would not recommend to implement as you have suggested.

    It is the same reason why you don't store first name last name, and middle initial in the same field.

    also what if a property is added in the middle, or removed in the middle?

    You should group the checkboxes (attributes) by their parent (noun), and place each in a table according to their parent. 1 column for each attribute.

    if thats not gonna work, or not robust enough for you then you can create a table that has a name, and a value. Store 1 row for each checkbox. that way boxes can be added or removed and it would not effect your application.

     

  • As stated by Ray in the post before, this data structure will cause endless maintainance problem in the future.

    To add my 2cents worth of thoughts, if due to some other design constrains etc, you have to store this string of 0s and 1s and you do not know the maximum length this string will extend to (hence u could not define the varchar(???) of your column), you can try to convert the binary-like data of 100101 to integer in your code before storing it in the database.

     

     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply