Re: Storing a tree structure in a table/database
Posted by: Chris Bassett
Date: February 17, 2018 01:01AM

I had one thought about this design, and what about if I used the same table I had outlined above, but is only for defining the folder structure, with slight modification:

So we would now have:

CREATE TABLE FolderStructure
(
folder_id bigint not null,
parent_folder_id bigint not null,
folder_name varchar(128) not null,
PRIMARY KEY(folder_id, parent_folder_id)
)


This way, entries with a parent_folder_id of 0 are assumed to be top-level/root level folders. Otherwise, subfolder entries would reference a use the parent_folder_id to reference another folder_id in the same table, thus building a hierarchy structure.

I'm not exactly sure, though, how I would go about querying the database to read back the folder structure so that it can be used to populate a Visual C# TreeView control (I'll be using Visual Studio as I'm writing a C# Windows desktop application). That part I still need to figure out. I would assume that root entries could be read easily (just any entry that has 0 for a parent_folder_id). It's the nested folders that will take some figuring out.

Options: ReplyQuote


Subject
Written By
Posted
Re: Storing a tree structure in a table/database
February 17, 2018 01:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.