How can we create a directory structure in database by using on one single table, we have 300 folders(that is folder in folder) and we to keep track from base to root, and also to write down the query to iterate from any point to root.. and we dont want to code it just by database query.
Asked
Active
Viewed 259 times
-1
-
1Easy. there will be 3 fields. 1. id 2. folder_name 3. parent_id – rawat0419 Aug 21 '15 at 07:28
2 Answers
0
Use it like this
There will be 3 fields
id
folder_name
parent_id
parent_id be the id of the same table of the parent folder
In this way you can keep track of any folder from root

rawat0419
- 136
- 9
0
There are different ways to do it. If you are using SQLServer you can make use of HeirarchyId
. Please refer to the below link.
Or you can can have a simple table with
FolderId
FolderName
ParentFolderId
How to store directory / hierarchy / tree structure in the database?

Community
- 1
- 1

Sateesh Pagolu
- 9,282
- 2
- 30
- 48