Re: [sqlite] Best method to create a database with a tree structure?
On Mon, Jan 19, 2004 at 06:52:41AM +0800, John Scott wrote: > > Hello folks, > > I am thinking of to create a database with a tree structure. > ... Hi, A very interesting way is described in the excellent book "Advanced SQL" by Joe Celko: basically, a tree can be viewed as a set of (sub-)sets. The root is the bigger set because it contains all the others. Imagine you have a tree of person names: Foo | | | aaa bbb | ccc A node is a record of the following table : CREATE TABLE Person ( name char(3), left integer, right integer ); And the above tree can be described with these records : NAME LEFT RIGHT Foo 1 8 aaa 2 5 ccc 3 4 bbb 6 7 I hope this example will give you the general idea. I'm sure you can find much more information about this method on Google. Regards, Stephane. -- <[EMAIL PROTECTED]> - <[EMAIL PROTECTED]> (\(__)/) FreeBSD Francophone : www.freebsd-fr.org `(QQ)' Club Unix/Log. libres Cosne/Loire : www.cosnix.org) ( (o o) % ATTAC : www.attac.org `--' - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [sqlite] Best method to create a database with a tree structure?
Hi Martin, You are talking about standard Parent/Child relationships here but because you have unlimited number of entries you fold it into one table and have a Parent_ID column. So if you have your required details as being these columns Name SomethingElse Then a standard table might be Name_ID Name Somethingelse adding the parent id column would be Name_ID Name Somethingelse Parent_ID or Create Table TableName ( Name_ID INTERPER PRIMARYKEY , Name , Somethingelse , Parent_ID ) Now all you need to do is fill in the details , PARENT_ID = 0 means it has no parents (or leave it NULL if you want) When you retrieve the rows you always do select * from Tablename where Parent_ID = 2 (or what ever) regards Greg O - Original Message - From: John Scott To: [EMAIL PROTECTED] Sent: Monday, January 19, 2004 9:52 AM Subject: [sqlite] Best method to create a database with a tree structure? Hello folks, I am thinking of to create a database with a tree structure. BUt it seems to be a hard work. I would like to have a tree structure embbeded into the database like: Root folder which contains two other folders "books" and "music". If a click on books, only the entries in the database which belong to the folder bools under root should be displayed. Does someone have a good idea?? Thanks, Martin - 每天都 Yahoo!奇摩 海的顏色、風的氣息、愛你的溫度,盡在信紙底圖 信紙底圖
[sqlite] Best method to create a database with a tree structure?
Hello folks, I am thinking of to create a database with a tree structure. BUt it seems to be a hard work. I would like to have a tree structure embbeded into the database like: Root folder which contains two other folders "books" and "music". If a click on books, only the entries in the database which belong to the folder bools under root should be displayed. Does someone have a good idea?? Thanks, Martin - 每天都 Yahoo!奇摩 海的顏色、風的氣息、愛你的溫度,盡在信紙底圖 信紙底圖