陷入数据库结构与许多种类[重复]

时间:2022-10-04 10:40:04

This question already has an answer here:

这个问题在这里已有答案:

I'm creating a structure of DB by E/R Diagram, but I'm stuck since some days on this problem. Probably I'm wrong in the way I'm doing it, so if you think I can do it in a better way, would be lovely :)

我正在通过E / R Diagram创建一个DB结构,但是几天后我就遇到了这个问题。可能我做错了,所以如果你认为我能以更好的方式做到这一点,那就太可爱了:)

The scenario is: I have N users who owns N sensors, not all the sensors (in the future could increase to 300 kinds of sensors) have the same features(columns), so I suppose I need a table for each sensor and then list the inside the values collected.

场景是:我有N个用户拥有N个传感器,并非所有传感器(将来可以增加到300种传感器)具有相同的功能(列),所以我想我需要一个表用于每个传感器然后列出收集的价值内部。

陷入数据库结构与许多种类[重复]

I have some doubts regarding how to referentiate the tabless for "kind sensor"-"Sensors" wich columns should I put on the "sensor" table, also in this way I will get many tables. Do yo have any hint?

我有点怀疑如何将表格用于“种类传感器” - “传感器”我应该把列放在“传感器”表上,同样这样我会得到很多表。你有什么提示吗?

3 个解决方案

#1


1  

Simplest and easiest way to do it is to make all specific columns in your table "sensors" and have one foreign key to another table "sensor_type" which is consisted of 2 columns

最简单和最简单的方法是将表中的所有特定列设置为“传感器”,并将一个外键设置为另一个表“sensor_type”,该表由2列组成

table "sensor_type"
id_type  - identifier (primary key)
description - description of your sensor (heat, temperature sensor ... )

Your table sensor then looks like

你的桌面传感器看起来像

table "sensor"
id_sensor                       identifier (primary key)
id_type                         foreign key references sensor_type table
size                            default null, if type 2 or 3 then something
weight                          default null, if type 1 and 3 then something
etc...

You need to understand this is probably one of many solutions which can solve your problem. I hope it helps.

您需要了解这可能是解决您问题的众多解决方案之一。我希望它有所帮助。

#2


1  

May be it's better to introduce Many to many relationship between sensors and features they have? For example like this:

可能更好地介绍传感器和它们具有的功能之间的多对多关系?例如这样:

Sensors
 sensor_id (pk)
 type

Features
 feature_id (pk)
 name

SensorsFeatures (Ownership table)
 sensor_id (foreign key to Sensors.sensor_id)
 feature_id (foreign key to Features.feature_id)

If you need to store values of these features (weight, height, width,...) , you can do it in SensorsFeatures table.

如果需要存储这些功能的值(重量,高度,宽度......),可以在SensorsFeatures表中执行。

#3


0  

You should add new table e.g. sensor_type for all sensors, where each row will be the sensor with uniq id which can be added to user.

您应该添加新表格,例如所有传感器的sensor_type,其中每一行都是具有uniq id的传感器,可以添加到用户。

The idea is to separate sensors with type or something else which is the most common thing beaten sensors.

我们的想法是将传感器与类型或其他东西分开,这是最常见的传感器。

#1


1  

Simplest and easiest way to do it is to make all specific columns in your table "sensors" and have one foreign key to another table "sensor_type" which is consisted of 2 columns

最简单和最简单的方法是将表中的所有特定列设置为“传感器”,并将一个外键设置为另一个表“sensor_type”,该表由2列组成

table "sensor_type"
id_type  - identifier (primary key)
description - description of your sensor (heat, temperature sensor ... )

Your table sensor then looks like

你的桌面传感器看起来像

table "sensor"
id_sensor                       identifier (primary key)
id_type                         foreign key references sensor_type table
size                            default null, if type 2 or 3 then something
weight                          default null, if type 1 and 3 then something
etc...

You need to understand this is probably one of many solutions which can solve your problem. I hope it helps.

您需要了解这可能是解决您问题的众多解决方案之一。我希望它有所帮助。

#2


1  

May be it's better to introduce Many to many relationship between sensors and features they have? For example like this:

可能更好地介绍传感器和它们具有的功能之间的多对多关系?例如这样:

Sensors
 sensor_id (pk)
 type

Features
 feature_id (pk)
 name

SensorsFeatures (Ownership table)
 sensor_id (foreign key to Sensors.sensor_id)
 feature_id (foreign key to Features.feature_id)

If you need to store values of these features (weight, height, width,...) , you can do it in SensorsFeatures table.

如果需要存储这些功能的值(重量,高度,宽度......),可以在SensorsFeatures表中执行。

#3


0  

You should add new table e.g. sensor_type for all sensors, where each row will be the sensor with uniq id which can be added to user.

您应该添加新表格,例如所有传感器的sensor_type,其中每一行都是具有uniq id的传感器,可以添加到用户。

The idea is to separate sensors with type or something else which is the most common thing beaten sensors.

我们的想法是将传感器与类型或其他东西分开,这是最常见的传感器。