一个数据库单元中有多个元素 [英] Multiple elements in one database cell

查看:113
本文介绍了一个数据库单元中有多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是数据库设计应该如何应用这种情况:



主表:

  ID |名称| number_of_parameters |参数

参数表格

 参数|参数|参数

参数表中的元素数量不变。 number_of_parameters 单元格定义应将多少参数表存储在下一个单元格中。



我有从对象思维转向数据库设计的问题。因此,当我们谈论对象时,一行的参数与 number_of_parameters 一样多。



清楚了。什么是设计这种数据库的正确方法。如果有人可以提供一些SQL语句来获取它,那将是很好的。



我想使用SQLite来创建这个数据库。

这个问题的主要目的是了解如何创建这样的架构。 div class =h2_lin>解决方案

关系方式是有两个表。主表具有ID,名称和尽可能多的其他通用参数。参数表包含从主表中的ID到参数名称和参数值的映射;主表ID应该是外键,并且ID和名称的组合应该是唯一的。



参数的数量可以通过计算行数具有特定的ID。


The question is how database design should I apply for this situation:

main table:

ID | name | number_of_parameters | parameters

parameters table:

parameter | parameter | parameter

Number of elements in parameters table does not change. number_of_parameters cell defines how many parameters tables should be stored in next cell.

I have problems to move from object thinking to database design. So when we talk about object one row has as much parameters as number_of_parameters says.

I hope that description of requirements is clear. What is the correct way to design such database. If someone can provide some SQL statments to obtain it it would be nice. But the main goal of this question is to understand how to make such architecture.

I want to use SQLite to create this database.

解决方案

The relational way is to have two tables. The main table has an ID, name and as many other universally-present parameters as possible. The parameters table contains a mapping from an ID in the main table to a parameter name and a parameter value; the main table ID should be a foreign key, and the combination of ID and name should be unique.

The number of parameters can be found by just counting the number of rows with a particular ID.

这篇关于一个数据库单元中有多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆