Describes the directory structure in which the files are stored in FileTables.
You can use the following three functions to work with FileTable directories in Transact-SQL:
To get this result | Use this function |
---|---|
Get the root-level UNC path for a specific FileTable or for the current database. | FileTableRootPath (Transact-SQL) |
Get an absolute or relative UNC path for a file or directory in a FileTable. | GetFileNamespacePath (Transact-SQL) |
Get the path locator ID value for the specified file or directory in a FileTable, by providing the path. | GetPathLocator (Transact-SQL) |
To keep code and applications independent of the current computer and database, avoid writing code that relies on absolute file paths. Instead, get the complete path for a file at run time by using the FileTableRootPath (Transact-SQL) and GetFileNamespacePath (Transact-SQL)) functions together, as shown in the following example. By default, the GetFileNamespacePath function returns the relative path of the file under the root path for the database.
USE database_name; DECLARE @root NVARCHAR(100); DECLARE @fullpath NVARCHAR(1000); SELECT @root = FileTableRootPath(); SELECT @fullpath = @root + file_stream.GetFileNamespacePath() FROM filetable_name WHERE name = N'document_name'; PRINT @fullpath; GO
You cannot store more than 15 levels of subdirectories in the FileTable directory. When you store 15 levels of subdirectories, then the lowest level cannot contain files, since these files would represent an additional level.
The NTFS file system supports path names that are much longer than the 260-character limit of the Windows shell and most Windows APIs. Therefore it is possible to create files in the file hierarchy of a FileTable by using Transact-SQL that you cannot view or open with Windows Explorer or many other Windows applications, because the full path name exceeds 260 characters. However you can continue to access these files by using Transact-SQL.
The full path to a file or directory stored in a FileTable begins with the following elements:
The resulting hierarchy looks like this:
This directory hierarchy forms the root of the FileTable's file namespace. Under this directory hierarchy, the FILESTREAM data for the FileTable is stored as files, and as subdirectories that can also contain files and subdirectories.
It is important to keep in mind that the directory hierarchy created under the instance-level FILESTREAM share is a virtual directory hierarchy. This hierarchy is stored in the SQL Server database and isn't represented physically in the NTFS file system. All operations that access files and directories under the FILESTREAM share and in the FileTables that it contains are intercepted and handled by a SQL Server component embedded in the file system.
This directory hierarchy observes the following semantics:
The following table describes the interaction between the is_directory column and the file_stream column that contains the FILESTREAM data in a FileTable.
is_directory value | file_stream value | Behavior |
---|---|---|
FALSE | NULL | This is an invalid combination that is caught by a system-defined constraint. |
FALSE | The item represents a file. | |
TRUE | NULL | The item represents a directory. |
TRUE | This is an invalid combination that is caught by a system-defined constraint. |
When the database that contains FILESTREAM or FileTable data belongs to an availability group: