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". Naturally, each species can be found in multiple sub regions. The subRegions table had "id", "name", and "coordinates" as it fields.
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?
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. The table will contain species_id and subRegion_id as a composite primary key.
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.
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. 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.
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.