in reply to Trees in SQL, adjacency lists and sorting.
The next bit is DBMS specific but you also need to define the primary keys: (node.node_name) and (node_node.parent_fk, node_node.child_fk) and the foreign key constraints: node.node_name -> node_node.parent_fk and node.node_name -> node_node.child_fk.CREATE TABLE node (node_name VARCHAR(32) NOT NULL) CREATE TABLE node_node ( parent_fk VARCHAR(32) NOT NULL, child_fk VARC +HAR(32) NOT NULL )
The advantage of this over the single table solution is that it is normalised and can be extended into a multi-type, multi-tree model without having to keep adding foreign keys to the master table.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Trees in SQL, adjacency lists and sorting.
by saberworks (Curate) on Jan 06, 2006 at 19:25 UTC | |
by demerphq (Chancellor) on Jan 10, 2006 at 16:27 UTC | |
by DungeonKeeper (Novice) on Jan 09, 2006 at 10:01 UTC | |
by saberworks (Curate) on Jan 09, 2006 at 23:00 UTC | |
by DungeonKeeper (Novice) on Jan 10, 2006 at 09:35 UTC | |
by saberworks (Curate) on Jan 10, 2006 at 16:00 UTC |