Обсуждение: Re: [GENERAL] Implementing hierarchy

Поиск
Список
Период
Сортировка

Re: [GENERAL] Implementing hierarchy

От
Дата:
Rob Walker writes:
 > > I am trying to write code to access a product catalog (more as a learning
 > > exercise than anything else) and need to implement some sort of searchable
 > > hierarcy.  For example:
 > >
 > > Computer Hardware (toplevel)
 > >    Hard Drives
 > >       Internal
 > >          SCSI
 > >             Fast SCSI
 > >             Wide SCSI
 > >             SCA
 > >
 > > Assuming these 'categories' are all in the same table as follows:
 > >
 > > prkey (primary key)
 > > descr varchar
 > > parent (for subcategories, toplevel parent is 0)
 >
 > I don't know if there is a 'right' way to do this, but I have done something
 > similar having an extra table that contains a tuple listing (node, ancestor)
 > pairs.  This is kept in sync with the main table using a couple of triggers.
 > The code is at the end
 >
 > A sequence is used for the primary key in the main table, and the hierarchy
 > is then implicit since you can't create a child before the parent (at least
 > my application doesn't let you move an existing child to another parent).

Here is a web page that may help. It explains something along the same
lines.

http://www.dbmsmag.com/9809d05.html

--
Patrick D. Logan        mailto:patrickdlogan@home.com