简体   繁体   中英

MySQL database storing of unknown number of values

I'm new to MySQL and I'm trying to create a database using Netbeans. I want to store into this database a name (ie 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM