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: FileTableIn addition to the predefined, fixed schema <strong>of</strong> FileTables, several additional databaseobjects are created when creating FileTables. <strong>The</strong>se objects include DEFAULTconstraints to set appropriate values for many <strong>of</strong> the metadata columns in the FileTable,CHECK constraints to ensure that no invalid column values can be added (such as anon-NULL file_stream column if the row refers to a folder and not a file) and UNIQUEconstraints to ensure that each full path is unique. <strong>The</strong>re is even a foreign key for theparent_path_locator column to ensure that it refers to a valid folder.Creating folder structures using the HIERARCHYIDdata typeFileTable supports folder structures with a maximum depth <strong>of</strong> 15 subfolders. Even thougha maximum <strong>of</strong> 15 subfolders is supported, you will probably create a maximum <strong>of</strong> 14subfolders, because it's not possible to create a file in the 15th level subfolder (as it wouldcreate a 16th level item).<strong>The</strong> folder structure is implemented using the HIERARCHYID feature introduced with<strong>SQL</strong> <strong>Server</strong> 2008. While a complete discussion <strong>of</strong> the HIERARCHYID data type is beyondthe scope <strong>of</strong> this book, it is valuable to review some <strong>of</strong> the concepts and basic queries thatcan be performed using HIERARCHYID fields.In a FileTable, the primary key is a field <strong>of</strong> type HIERARCHYID and even though it's easyto query the parent <strong>of</strong> a given HIERARCHYID value, the parent in the hierarchy is storedin the parent_path_locator field. To keep this discussion focused on the basics <strong>of</strong>HIERARCHYID, and since we have yet to discuss how to create FileTables, we'll use asample table that does not actually contain any <strong>FILESTREAM</strong> data, but just the hierarchystructure and a name field, as shown in Listing 11-1.392

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

Saved successfully!

Ooh no, something went wrong!