4

Is there a way to create directories in a FileTable without using File I/O APIs? Is it just as simple as creating a SQL INSERT statement?

This is my first experience with SQL Server 2012 and I'm not familiar with the limits of the FileTable from within SQL Server.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173

1 Answers1

7

The following worked for me. Hopefully this helps out someone else.

INSERT INTO FileTable0 (name,is_directory,is_archive) VALUES ('Directory', 1, 0);
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
  • This is partially right. This only covers adding a directory in the root. Adding a subdirectory, or creating a path without any of the parent directories created, are not handled by this. – Rhyous Jun 21 '16 at 20:56
  • @Rhyous - you are correct, for [adding subdirectories see this related SO post](http://stackoverflow.com/q/10485978/175679). You must have a parent defined before you can create any children. You could implement a simple algorithm to do the behavior you are seeking using a combination of this post and the other and checking whether a given directory exists already. – SliverNinja - MSFT Jun 22 '16 at 01:05
  • 1
    Thanks. Found that yesterday. I am taking this and making some SQL functions. Maybe I'll share them on GitHub when I am done. – Rhyous Jun 22 '16 at 14:57