Results 1 to 14 of 14
Aug 14, 2012, 09:20 #1
- Join Date
- Feb 2011
- 0 Post(s)
- 1 Thread(s)
noob question, possible to have variable number of fields in a record?
Hi, I'm a mysql noob, but I'm in a position for a project where I'm hiring devs and making strategic decisions on storing data so I would love any help with this question.
The data I need to store will have a varying number of key fields per record.
Some example key / value pairs, I'm assigning 100 for each value as the problem lies with the keys
IDdata 1 : dataA = 100 , dataB = 100 , dataC = 100
IDdata 2 : dataA = 100 , dataB = 100 , dataC = 100 , dataC1 = 100 , dataC2 = 100 , dataD = 100
IDdata 3 : dataA = 100 , dataA1 = 100 , dataA1a = 100 , dataA1b = 100 , dataA2 = 100 , dataB1 = 100
IDdata 4 : dataA = 100 , dataB = 100 , dataC = 100 , dataD = 100 , dataD1 = 100 , dataD1a = 100
as you can see just to store the above I would need a table really wide where the column headers cover every single possible variation of key.
I'm guessing that mysql tables must specify the number of columns when they are created right?
The solution I am considering is to have a table with just two columns
IDdata and data string
Then I could store the key value pairs concatenated in a string with fields separated by colons and semi colons or commas or something.
When retrieving a record I would instead retrieve the string and parse it. That way if a record went four levels deep on its A group of data and another record only went one level deep but went up to F number of groups it would be cope.
Please tell me if I am going at this right or wrong with regards to mysql