I have a simple application in which users submit data into a table.
There are currently 3 fields the user can pass values to at the moment. I'm trying to find a solution where the number of description columns can vary, depending on the description list created by the user.
So far I have considered:
My current table is something like this:
CREATE TABLE `user_input` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`description_list_id` int(11) NOT NULL,
`description1` int(11) NOT NULL,
`description2` int(11) NOT NULL,
`description3` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Are there any other solutions?
There is no precise guidance. A table could be as little as one column or as many as the max, 1024. However, in general, you'll probably see no more than 10-15 columns in a table in a well normalized database.
For the columns in a table, there is a maximum limit of 1024 columns in a table. SQL Server does have a wide-table feature that allows a table to have up to 30,000 columns instead of 1024.
The number of columns ranges from 2 to 69: most datasets measure few variables, but several measure 30 or more. We consider a case study using SQL-as-a-Service to support "instant analysis" of weakly structured relational data at a multi-investigator science retreat.
To find the number of columns in a MySQL table, use the count(*) function with information_schema. columns and the WHERE clause.
Definitely option #2. Normalizaing is always the best option in a scenario like this. You are correct that it is more work, but you are overcoming the inevitable issue when you will need more than 15 descriptions.
The second solution is preferable in terms of flexibility. If tomorrow you need to add more description fields with the first solution you will need to modify the table and the code to manage it.
The second solution can require a bit more work now but then it will handle 2 like 200 descriptions.
The first approach is more a quick and dirty solution for a small problem, the second also a good exercise if you have time to try something new.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With