建模树或图形SQL:如何分离节点和节点信息的属性 [英] modelling trees or graphs SQL: how to separate properties of nodes and nodes information

查看:123
本文介绍了建模树或图形SQL:如何分离节点和节点信息的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 polytree 建模概念本体。

使用边缘列表模型,它会(

Using the edge list model it would be:

CREATE TABLE nodes(
  nodeID CHAR(1) PRIMARY KEY
);

CREATE TABLE edges(
  childID CHAR(1) NOT NULL,
  parentID CHAR(1) NOT NULL,
  PRIMARY KEY(childID,parentID)
);

我的问题是如何在SQL中建模,以便节点可以具有其他属性,如类型 。例如。

My problem is how can I model it in SQL so that nodes can have other properties like "types". Eg.

(father-node) **Music**  



has

(child-node) **jazz** [type: genre], **soul** [type: genre]
(child-node) **concert** [type: performed], **DJ set** [type: performed]


推荐答案

您应该检查Celkos嵌套集模型, http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

You should check out Celkos nested set model, http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

但是无论如何只需将genre id添加到您的节点表中

But anyway just add genre id to your nodes table

CREATE TABLE nodes(
  nodeID CHAR(1) PRIMARY KEY
  genre_id
);

这篇关于建模树或图形SQL:如何分离节点和节点信息的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆