Programming files in a folder
I am trying to find the best way to create a filesystem in sql. I am making a site that will use a similar system like explorer in windows.
You open your c: drive and you see multiple folders and files there and you open one folder and you see more files and folders there.
So what I'm asking is, can I use one table for this and just give the parent id number or what?
I have it in my head. You create a Primary folder, it gets u_id = 1. Then I create a file in that folder, it gets u_id = 2 and p_id = 1, so I know it right there? the same with folders.
This will all be in the same table, but I can't help thinking that there is some major flaw in this.
a source to share
I would tackle this in several ways:
Add a table Folders
with these columns and whatever you need:
FolderId [INT]
ParentFolderId [NULL INT]
Key [VARCHAR(MAX)]
What holds the key is each ParentId of the current child like this:
19-144-444-
That it allows you to easily find child folders without recursion.
Add a table Files
with these columns:
FileId [INT]
FolderId [INT]
For the most part, files will have a lot more metadata associated with them, so there is no reason to overuse one table
a source to share