开发者

trees and tables in DB2

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?

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

trees and tables in DB2


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)

Create a primary key for ID column. And a foreign key for parentComponent referencing the same table with the ID column.

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

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

And Stored procedures for

  • Return a table with the rows ordered by a specific tree traversal (Breadth-first, Depth-first)

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜