在 MySQL 中创建分类表
我正在创建一个植物数据库,其中植物将按其分类法进行组织:
生命 领域 王国 门 班级 命令 家庭 属 <
I am creating a botanical database where the plants will be organized by their taxonomy:
Life
Domain
Kingdom
Phylum
Class
Order
Family
Genus
Species
I was considering using the example put forth by the article Managing Hierarchical Data in MySQL, however it is adding the above list as records inside the table....and I'm not sure if that is the best thing to do since I will be having multiple species per genus and multiple genus per family and so on. What would you suggest is the best way to approach this problem. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用了类似的数据,并将其分为两部分。在 PostgreSQL 语法中。
首先是分类结构(科、属、种……):
其次是植物数据的描述和存储:
I worked with similar data, and I made it in 2 parts. In PostgreSQL syntax.
First is taxonomy structure (Family, Genus, Species, ...):
Second is description and storing of botanical data:
我不确定我是否真的相信那篇文章。当类别本身可变时,需要图形结构。例如,分类学家突然决定在属和种之间添加三个新的级别,等等。
来自文章:
实际上,它正是它的用途:
http://en.wikipedia.org/wiki/Hierarchical_database_model
我首先会编写一个连接所有表的视图,以便将这些表作为列:
现在您可以以任何您喜欢的方式查询该视图,而不必担心任何连接。简单
:)
I'm not sure I really buy into that article. Graph structures would be needed when the categories itself are mutable. Such as, all the sudden taxonomists decided to add three new levels between genus and species, and so on.
From the article:
Actually, its exactly what it is intended for:
http://en.wikipedia.org/wiki/Hierarchical_database_model
I would first write a view that joined all of your tables so that you would have these as your columns:
Now you can query that view any way you like and not have to worry about any joins. Easy
:)
您可以从 http://itis.gov 下载完整的分类数据,该数据或多或少每月更新一次。他们提供的数据包括一个物化路径——数据库中的每个物种都有一个包含其之上所有级别的字符串,例如面包屑字符串或文件系统路径。
我在演示文稿中使用这些数据设计了一个演示分层数据模型 。我将物化路径数据转换为闭包表。
You can download complete taxonomy data from http://itis.gov and the data is updated more or less monthly. The data they provide includes a Materialized Path -- every species in the database has a string of all the levels above it, like a breadcrumbs string or a filesystem path.
I used this data to design a demo in my presentation Models for Hierarchical Data. I converted the materialized path data into Closure Table.
听起来更像是一张图表。我想知道 NEO4J 是否是更好的选择。
It sounds more like a graph. I'd wonder if NEO4J would be a better choice.
有多种方法可以在关系数据库中表示分层数据,尽管 NoSQL 解决方案可能更容易使用,如 @duffymo 提到的。因此,假设使用 RDBMS,查看我的问题关于该主题列举了六种可能性。对于您的情况,我会引导一条具体化的路径,以便轻松查看家谱。如果层次结构定期更改,我可能还会将模型建模为邻接列表,并使用触发器更新具体化路径。
There are several ways of representing hierarchical data in a relational database, albeit a NoSQL solution might be easier to work with as @duffymo mentioned. So assuming an RDBMS, see my question on the topic for an enumeration of a half dozen possibilities. For your situation, I would lead with a materialized path to make seeing the family tree easy. If the hierarchy changes regularly I would probably also model as an adjacency list and update the materialized path using a trigger.