0

I want to store a tree of all files and directories in the database.

For my needs, the most appropriate structure for folders is:

CREATE TABLE [Dirs] ([HID] hierarchyid NOT NULL, [FullPath] nvarchar(3800) NOT NULL);

what is the best way to transform a path into a hierarchyid?

INSERT INTO [Dirs] VALUES (???, 'c:'), (???, 'c:\Users'), (???, 'c:\Users\User1'), (???, 'c:\Users\User2')
Vexator
  • 181
  • 3
  • 9

1 Answers1

-1

I hope this answers your question, hierarchyid for the paths would be:

/1/ for c:
/1/1/ for c:\Users
/1/1/1/ for c:\Users\User1
/1/1/2/ for c:\Users\User2
Neeraj Agarwal
  • 1,059
  • 6
  • 5
  • This doesn't answer the *how* part of the question – Rachel Ambler Nov 11 '19 at 20:09
  • @RachelAmbler The ??? for values in OP question lead me to believe that he was asking for what values he should be inserting into the row of the table to represent the structure of his folder not how to calculate those values. There is no "how" word in the question. You can post a question if you wish to know how to calculate these values. – Neeraj Agarwal Nov 13 '19 at 02:43