DB2中的树和表 [英] trees and tables in DB2

查看:75
本文介绍了DB2中的树和表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望您对我拥有的这张图有所帮助。我想找到一种方法来编写脚本来创建一个名为COMPS的表,以表示该组件/子组件
树结构,作为边缘列表。图。我可以将这些名称用于表COMPONENT,SUBCOMPONENT,SUBCOMPCOUNT的列。有想法吗?

I would like your help about this graph which I have.I would like to find a way how write a script to create a table named COMPS to represent this component/subcomponent tree structure, as an edge list for the graph. I can use these names for the columns of the table COMPONENT, SUBCOMPONENT, SUBCOMPCOUNT. Any ideas?

类型b的组件出现在
组件a的结构中的多个位置。但是组件b的结构是相同的,而不管其位置
组件d也出现在各个不同的位置,但是类型d的所有对象都是
的同类对象

Components of type b occur in more than one place in the structure of component a. But the structure of component b is the same, regardless of its position Component d also occurs in various different locations, but all objects of type d are the same kind of object

推荐答案

您应该按照表述创建表格以存储结构

You should create a table as you say in order to store the structue

create table graph (
ID int not null,
COMPONENT char(2) not null,
ParentComponent int)

为ID列创建主键。

然后,您可以创建一组UDF和存储过程来检索值,或打印该表。树结构。例如,用于

Then, you can create a set of UDF and stored procedure to retrieve values, or to print the tree structure. For example, UDFs for


  • 的UDF检索根节点

  • 树中节点的数量

  • 给定节点的子节点数量

  • 给定节点的父级ID。

  • Retrieve the root node
  • Quantity of nodes in the tree
  • Quantity of sons of a given node
  • The Parent ID of a given node.

和存储过程


  • 返回一个表,其中按特定的树遍历顺序对行进行排序(宽度优先,深度优先)

您甚至可以创建检查约束来提供创建图形的规则。例如,根节点为0,其他任何人都不能拥有此ID,并且ID是最小值。

You can even create check constraints to provide rules to create the graph. For example, root node is 0, no one else can have this ID, and the is the lowest value.

您需要在图形中执行哪些操作?

What operations do you need to do in you graph?

这篇关于DB2中的树和表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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