[英]Relational database structure request
I am developing an relational database and am stuck on how to accomplish something. 我正在开发一个关系数据库,并且坚持如何完成某件事。
I have many tables, but two of which are the issue. 我有很多表,但是其中两个是问题。 I have a table of several thousand marine species, called "species".
我有一个表,有数千种海洋物种,称为“物种”。 I have another table that contains the global oceans divided into 188 different sub regions, called "subRegions".
我有另一个表格,其中包含被划分为188个不同子区域的全球海洋,称为“ subRegions”。 Naturally, each species can be found in multiple sub regions.
自然地,每个物种都可以在多个子区域中找到。 The subRegions table had "id", "name", and "coordinates" as it fields.
subRegions表具有“ id”,“ name”和“ coordinates”字段。
It is easy to set a foreign key to the subRegions id, from the species id, but how to set this so that multiple regions can be displayed, per species, at once? 从物种ID到subRegions ID设置外键很容易,但是如何设置它以便一次显示每个物种多个区域?
Any ideas? 有任何想法吗?
So what you have is a many-to-many relationship with optional participation in each. 因此,您所拥有的是多对多关系,每个关系中都有可选的参与。 So you'll find your species in none, one or many subRegions;
因此,您将在一个,一个或多个子区域中找到您的物种; each subRegion may contain none, one or many species.
每个子区域可能不包含一个物种,也可以包含多个物种。
Implementing this, you would have an intermediary table to record the relationship. 实现这一点,您将有一个中介表来记录关系。 That is your new table would be called speciesSubRegions.
那就是您的新表将被称为speciesSubRegions。 The table will contain species_id and subRegion_id as a composite primary key.
该表将包含species_id和subRegion_id作为复合主键。
The relationship then looks like species has a one-to-many relationship with speciesSubRegions with optional participation on the species side and mandatory participation on the speciesSubRegions side. 这样,该关系看起来就像物种与物种子区域具有一对多关系,在物种方面具有可选参与关系,而在物种子区域方面具有强制参与关系。
Then subRegions has a one-to-many relationship with speciesSubRegions which is optional on the subRegions side and mandatory on speciesSubRegions. 然后,子区域与物种子区域具有一对多关系,这在子区域侧是可选的,而在物种子区域是强制性的。
Clear as mud? 像泥一样清澈?
Relating species and sub regions via an intermediary table offers a few advantages, however I believe for some applications it may be a bit excessive to create another table. 通过中间表关联物种和子区域提供了一些优势,但是我认为对于某些应用程序来说,创建另一个表可能有点多余。 I realize this question has already been addressed, however below I have included a different way to accomplish the objective without needing to create an additional table.
我意识到这个问题已经解决,但是下面我提供了一种无需创建额外表即可实现目标的不同方法。
A simple and quick way to accomplish relating species with multiple sub regions. 一种简单快速的方法来完成具有多个子区域的相关物种。
Filemaker treats each return as a different value for the relationship, so at this point you could do a number of things to display the related data depending on the setup of your application. Filemaker将每个返回值视为关系的不同值,因此,根据您的应用程序的设置,此时您可以做很多事情来显示相关数据。
If you are selecting a species from a portal you could set a script trigger to set the "current_species_id" field to the ID of the selected portal row, and then have another portal based on subRegions2 to display associated sub regions. 如果要从门户网站中选择物种,则可以设置脚本触发器以将“ current_species_id”字段设置为所选门户网站行的ID,然后使另一个基于subRegions2的门户网站显示关联的子区域。 You would then be able to do whatever with those sub regions.
然后,您将可以对那些子区域执行任何操作。 Select for more information, or to create a new window.
选择以获取更多信息,或创建一个新窗口。 This is just another way to accomplish the same objective, but more dependent on relationships than a new table.
这只是实现同一目标的另一种方式,但是与新表相比,它更依赖于关系。 Different tools for the same job.
用于同一工作的不同工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.