Reputation: 29
I'm new to MySQL and I'm trying to create a database using Netbeans. I want to store into this database a name (i. e. string) and then an unspecified number of integers (I don't know in advance, how much would it be).
The only solution I've found so far is to write values of these integers into one string with a specified delimiter. Is there some kind of better approach to this problem (some kind of inflatable arrays or anything similar)?
I'm planning to use this database in Java program.
Upvotes: 0
Views: 167
Reputation: 840
The usual approach is to normalize the data:
Table name
id name
------------------
0 Foo
1 Bar
Table numbers
id nameId number
------------------
0 0 1
1 0 5
2 0 17
3 1 256
Each entry in name having 0..n entries in table numbers. The id-columns might not be necessary depending on other requirements of your application. This might lead to a design as suggested by Mr. M.
Upvotes: 1
Reputation: 1498
You could simply add multiple entries for the same name.
Name Number
------------
Test 1
Test 3
Test 5
Other 2
...
Then select all entries for that name when you read from it.
Upvotes: 1