Best practice question - checkbox values into multiple database columns or just one?
Can you please help me clear up something? When you have a range of checkbox options for one form question, is it generally considered better programming to place the checkbox responses strung together into one database column with a delimiter, or to have a separate column for each option? Why might someone choose to put the responses into separate columns?
I appreciate your insight.
You should never store multiple values in a single column in a database. That is one of the first things that you split out into separate records when normalising a database.
The best alternative is to have one column for the values but have a separate record for each. That way you can add another hundred c heckboxes to the form and not have to change the database structure.
If it is 100% guaranteed that the checkboxes cover all possible options and that they will never need to change then you could set up a separate column for each.
The main reason for never placing multiple values in one field in a database is that it does away with your ability to make simple queries on the database to extract information. It also makes defining the size of the field difficult. As a separate column you only need to store a single value of (eg. 0 or 1) to identify what the value is. With multiple values in the one field you don't know how big a field you will need to hold all the values (particularly if you need to add a few more values later).
And yes that means you will get *lots* of records and no that doesn't really matter, databases are designed to be fast a set-oriented operations, in fact they much faster at working with lots of smaller rows than ad fewer larger rows.
But that's something for a rainy sunday afternoon, for now you should use the classic normalization.
|All times are GMT +1. The time now is 10:23 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.