Interview-How To Store Directory Structure In Database

This was asked in an interview question that what will be the data structure schema of database if you  are given to save folder and they have files stored in it and also they contain sub folders in it.

So the best schema for this type of problem is that we will only require one table.
Yes one Table will do the job and more interestingly only 3 fields are enough to save  this information.

Field Name      –   Key                    – Data Type – Nullable

1). Dir                 – Primary Key   -int                   – Not Null
2). Dir_Parent –  Foreign Key   -int                   – Null Allowed
3). Description – Null                 -Varchar          – Not Null


Here on top is the description of how data will be save in database using one table and .


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s