什么数据库可以存储树?

发布于 2024-12-21 23:27:56 字数 204 浏览 2 评论 0 原文

是否有一个数据库可以存储树结构(例如嵌套注释)而不使用反模式等。
我认为 LDAP 就是其中之一,但是还有其他的吗?

我也需要能够索引childes。我需要它能够轻松地将分支从一个节点移动到另一个节点,并且能够快速读取+格式化。

我见过其他类似的问题。那些(对我来说)的问题是,他们问在 db XXX 中最有效的方法是什么,而我则问我应该使用哪个数据库。

Is there a DB out there that can store tree structures (like for nested comments) without using anti-patterns or such.
I think LDAP is one, but are there any others?

I need to be able to index childes as well. I need it to be easy to move a branch from one node to a different node and be fast to read + format.

I have seen other similar questions. The problem with those (for me) they ask what is the most efficient way to do it in db XXX, while I ask which DB I should use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱本泡沫多脆弱 2024-12-28 23:27:56

如果树很深,关系数据库将不是最好的选择。我推荐一个图形或对象数据库。

“存储评论”?喜欢以下博客或文章吗?如果是这样的话,我想说你可以假设它们不会那么深。十级评论树将是例外。

在这种情况下,使用外键的简单关系父/子关系就足够了:

CREATE TABLE IF NOT EXISTS article
(
    article_id integer not null auto_increment,
    comment_id integer,
    primary key(article_id),
    constraint fk_comment foreign key(comment_id) references article(article_id) on delete cascade on update cascade
);

Relational databases won't be the best for this if the tree is very deep. I'd recommend a graph or object database.

"Storing comments"? Like those following blogs or articles? If that's the case, I'd say that you can assume they won't be that deep. A ten level comment tree would be exceptional.

In that case, a simple relational parent/child relationship using foreign keys would be sufficient:

CREATE TABLE IF NOT EXISTS article
(
    article_id integer not null auto_increment,
    comment_id integer,
    primary key(article_id),
    constraint fk_comment foreign key(comment_id) references article(article_id) on delete cascade on update cascade
);
昔日梦未散 2024-12-28 23:27:56

当然,“关系数据库”强调的是“表”(二维关系)。

RDBMS 供应商有许多不同的选择。例如,DB2 有“层次结构”,Oracle 有“层次查询”:

更一般地说,大多数主要 RDBMS 产品(MS Sql Server、IBM DB2、Oracle)都已支持 XML。这提供了一种更强大、更便携的方法来操作结构化数据。

当然,在非 RDBMS 供应商中,还有更多处理非关系数据(如树)的选择。相应地,可移植性也较差——将自己锁定在一个“非 SQL 数据库”中往往会导致您无法轻松地将应用程序迁移到其他数据库。

底线:

如果您可以将 XML 与关系数据库结合使用,那么这可能是您的最佳选择。以下是一些很好的链接:

'希望这有帮助!

"Relational Databases", of course, emphasize "tables" (2-D relationships).

Among RDBMS vendors, there are many different alternatives. For example, DB2 has "hierarchical structures", and Oracle has "hierarchical queries":

More generally, most of the major RDBMS products (MS Sql Server, IBM DB2, Oracle) have all become XML-aware. This provides a more robust, portable approach to manipulating structured data.

Of course, among non-RDBMS vendors, there are even more alternatives for dealing with non-relational data (like trees). Correspondingly, there's less portability - locking yourself into one "non-SQL database" more often than not locks you OUT of easily migrating your application to a different database.

BOTTOM LINE:

If you can use XML with a relational database, that's probably your best option. Here are some good links:

'Hope that helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文