Re: Graph Schema

From: Neo <neo55592_at_hotmail.com>
Date: 13 Nov 2006 12:34:43 -0800
Message-ID: <1163450082.933807.126780_at_e3g2000cwe.googlegroups.com>


The nodes live in a table called "Node". The edges live in a table called "Dependency." Table Node has a 1 to many relationship with table Dependency. Table Dependency, in turn, has a 1 to many relationship with Node. Thus, two of the columns in table Dependency are actually just the primary key of Node. with a single select statement, you can find out that N1 is connected to N2, N3, and N4. Then you can use the values N2, N3, and N4 in seperate select statements to discover what they in turn are connected to (such as N2 being connected to N3 and N9).

So to encode:
"john like mary",
"john like sue",
"mary hate sue" and
"mary hate bob" the tables might be:

T_Node
nID Name
1 john
2 mary
3 sue
4 bob

T_Dependency
nID1 nID2 Name

1      2      like
1      3      like
2      3      hate
2      4      hate

and "SELECT nID2 FROM T_Dep WHERE nID1 = 1" would return mary(2) and sue(3)
and "SELECT nID2 FROM T_Dep WHERE nID1 = 2" would return sue(3) and bob(4),
and so on ...

What you are attempting is possible; however it has some limitations that may not apply in your case. For example, how would one related like and hate as opposites? How would one relate (john like mary) because (mary hate sue)? If you need this level of flexibility, it becomes impractical.

You may be interested in dbd, an experimental db that I have been developing. It handles such cases. See example at www.dbfordummies.com/example/ex133.asp If you have some data that you would like to model/query for fun in dbd, please post it or email me directly. Received on Mon Nov 13 2006 - 21:34:43 CET

Original text of this message