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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9: Investigating <strong>FILESTREAM</strong> DatabasesINNER JOIN sys.data_spaces dON d.data_space_id = t.filestream_data_space_idWHERE p.filestream_filegroup_id > 0/*TableName FileGroup FolderName--------- ------------- ------------------------------------Items1 NorthPole_fs1 041C0478-8EB6-4C65-B0AD-12E29DF69D09Items2 NorthPole_fs2 AEA2F2A4-4CA5-4790-AB16-1F78379D69C8*/Listing 9-10:Retrieving the <strong>FILESTREAM</strong> folders associated with each table in the current database.Note that, without the WHERE clause, two rows are returned for each table with<strong>FILESTREAM</strong> columns. <strong>The</strong> second row contains NULL as the filestream_guid value.<strong>The</strong>re are two rows in sys.system_internals_partitions for a single table with<strong>FILESTREAM</strong> columns. <strong>The</strong> difference seems to be in the filestream_filegroup_idfield that is set to "0" for the row that has the NULL in the filestream_guid field.If the <strong>FILESTREAM</strong> table is partitioned, <strong>SQL</strong> <strong>Server</strong> will create a root folder per partitionin the table. If you have partitioned <strong>FILESTREAM</strong> tables, you might need a slightlymodified version <strong>of</strong> the above query to determine the <strong>FILESTREAM</strong> folder names <strong>of</strong> eachpartition, as shown in Listing 9-11. It is interesting to note that <strong>SQL</strong> <strong>Server</strong> does not listthe NULL row we saw earlier when the table is partitioned; therefore, this query does nothave the same WHERE clause.SELECTt.Name AS TableName,sip.partition_number AS PartitionNumber,sip.filestream_guid AS FilestreamFolderFROM sys.system_internals_partitions sipINNER JOIN sys.partitions p ON p.partition_id = sip.partition_idAND sip.filestream_guid IS NOT NULLINNER JOIN sys.tables tON t.object_id = p.object_id342

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

Saved successfully!

Ooh no, something went wrong!