-1

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.

thebluephantom
  • 16,458
  • 8
  • 40
  • 83

2 Answers2

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