Re: How to represent a tree-structure in a relational database
От
Frank Joerdens
Тема
Re: How to represent a tree-structure in a relational database
Дата
Msg-id
20001213232514.A31376@rakete.joerdens.de
Ответ на
RE: How to represent a tree-structure in a relational database (Stuart Statman)
Список
Дерево обсуждения
Re: How to represent a tree-structure in a relational database Ron Peterson <ron.peterson@yellowbank.com>
On Wed, Dec 13, 2000 at 11:38:18AM -0800, Stuart Statman wrote: [ . . . ] > I would suggest, instead, to create a table that represents your hierarchy > without adding columns. For example : > > create table Category ( > CategoryID int4 not null primary key, > ParentCategoryID int4 not null REFERENCES Category (CategoryID), > CategoryName varchar(100) > ); > > Add a CategoryID with an FK reference to this table, and your work is done. > > Then adding, inserting, removing, or moving layers in the hierarchy becomes > quite simple. This also preserves hierarchical integrity, where subcategory > a of subcategory b will also remain a subcategory of category c if > subcategory b is a subcategory of subcategory c, where I'm not sure your > model will preserve or guarantee that. (Does that sentence deserve a prize?) Cool. That looks like my solution. I had actually seen it someplace before, but didn't make the connection with my problem. Ta, Frank
В списке pgsql-sql по дате отправления