Re: Modelling hierarchy in the relational database

From: BP Margolin <bpmargo_at_attglobal.net>
Date: Fri, 17 Aug 2001 18:38:43 -0400
Message-ID: <3b7d9b0b_3_at_news3.prserv.net>


Assuming you are using SQL Server, check out the section "Expanding Hierarchies" in the SQL Server Books Online.

You might also consider checking out "Advanced Transact-SQL for SQL Server 2000" by Itzik Ben-Gan and Tom Moreau for discussion and code related to modeling a hierarchical structure in a relational database.

Similarly, "SQL for Smarties" by Joe Celko has discussion and code related to modeling a hierarchical structure in a relational database. Joe's method is different from that in the book by Itzik and Tom. Joe's code is not SQL Server specific, but ANSI SQL-92, and so will require some changes to work in SQL Server.



BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which can be cut and pasted into Query Analyzer is appreciated.

"abracad" <abracad_at_nospam.com> wrote in message news:3b7d87c0.509669_at_news.freeserve.net...
> I am constructing a database to model hierarchy, e.g.
> A
> |
 B
> |
> C
>
> I envisage a table parent consisiting fields parent, child and would
> store records A,B and B,C. Would I also need to store record A,C?
>
> I.e. can SQL act recursively to determina all the children of a given
> node (could it retrieve B and C if I queried for the children of A
> with only records A,B and B,C stored?)
>
> Many thanks in advance for any help on this
Received on Sat Aug 18 2001 - 00:38:43 CEST

Original text of this message