简体   繁体   中英

How should I store this in MySQL?

I am planning on creating a web interface, in which users will create fields to store information from robot matches.

Each year the competition is different, and thus the information that needs to be recorded is different. Usually there are 5-15 pieces of information for each of the 6 robots on the playing field.

I had a couple of thoughts,
1.) take the input from a php page, and use it to create a table in the database.

2.) To somehow store the schema as a text string, and the same with the data.

Your thoughts and insight would be greatly appreciated.

If the information is straight forward, why not have one table with a schema like:

ID , year , user_id , attrib_name , attrib_value

Now users can click on Add Field on the form, 2 text boxes show up. In one they put in the name of the attribute and the other contains the info.

This way they can add as much info as they want and based on your architecture you can adjust the table to have something other than user_id , year as the identifiers for yearly entries.

Hope this helps!

If you are going to need many different fields, and they are all a string, you could create a robot_info table, and then a relation table with that. for example:

CREATE TABLE robot (
  robot_id int not null default 0 primary key auto increment,
  //stuff about the robot
);

CREATE TABLE robot_info (
  robot_info_id int not null default 0 primary key auto increment,
  field_type varchar(255),
  field_value varchar(255)
);

CREATE TABLE robot_info_relation (
  robot_id int,
  robot_info_id int
); 

This way any robot can have any number/combination of fields of info.

请参阅有关属性值模型的以下问题: 实体属性值数据库 -vs-strict- 关系模型-电子商务问题

如果值域逐年重叠,那么只需将它们的所有属性都放在表中,然后仅填充任何给定年份中的已知属性即可。

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