17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11: FileTableWe may also need to create a new file in a subfolder. We must ensure that we createthis new file in a valid hierarchy, which means that we must include the folder'spath_locator in the path_locator <strong>of</strong> this new record. As an example, Listing 11-19shows a simplified view <strong>of</strong> the structure we just created using Listing 11-17 andListing 11-18.SELECT CAST(path_locator AS VARCHAR(4000)), name,path_locator.GetLevel() AS 'level', is_directoryFROM Documents/*path_locator name level is_directory------------ ----------- ----- ------------/1.1.1/ ReadMe.txt 1 0/2.2.2/ Order Files 1 1*/Listing 11-19: Querying the contents <strong>of</strong> the Documents table.While the path_locator values you will find are more complex, the point is toillustrate that the file and the folder have a different hierarchyid (path_locator)value, but that the level in the hierarchy is both 1. <strong>The</strong> new file we want to add shouldhave a path_locator and level value like the ones shown in Table 11-2.path_locator name level/2.2.2/3.3.3/ NewFile.txt 2Table 11-2:path_locator value for the new file.We must create the new file record as a child <strong>of</strong> the Order Files folder, so we cannotuse the DEFAULT constraint on the path_locator column to let <strong>SQL</strong> <strong>Server</strong> create apath_locator value located in the FileTable root. Instead, we must first find the parentfolder's path_locator value and construct a new path_locator value that is a childvalue <strong>of</strong> the parent folder's path_locator. Listing 11-20 shows how this can be done.416

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!