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 2: Getting Started with <strong>FILESTREAM</strong>Loading the content to the VARBINARY(MAX) variable is unnecessary in the aboveexample. This additional step was added to make the code easier to follow. Listing 2-19shows another version <strong>of</strong> the code that does not use a staging variable, but instead insertsthe data directly into the table.-- Insert the data to the tableINSERT INTO Items( ItemID ,ItemNumber ,ItemDescription ,ItemImage)SELECT NEWID() ,'MS1001' ,'Micros<strong>of</strong>t Mouse' ,CAST(bulkcolumn AS VARBINARY(MAX))FROM OPENROWSET(BULK 'C:\temp\Micros<strong>of</strong>tMouse.jpg', SINGLE_BLOB) AS xListing 2-19:Loading a disk file directly into a <strong>FILESTREAM</strong> column.So, where did the data go? Well, the data we just loaded into the <strong>FILESTREAM</strong> columngoes to the <strong>FILESTREAM</strong> data container. <strong>The</strong> exact content <strong>of</strong> the source file is copiedto the correct location within the <strong>FILESTREAM</strong> data container; when <strong>SQL</strong> <strong>Server</strong> storesBLOB data in the <strong>FILESTREAM</strong> data container, an exact copy <strong>of</strong> the original binary chunkis stored in the file system. <strong>SQL</strong> <strong>Server</strong> does not change the content; nothing is added,modified, or removed. Also, there is a specific location for every <strong>FILESTREAM</strong> column inthe database. Listing 2-20 shows the file system map.C:\|-<strong>Art</strong>OfFS\|-Demos\|-Chapter2\|-NorthPole_fs\-- Filestream Data Container|-$FSLOG\-- Log Folder|-filestream.hdr -- Metadata File|-5a032731…dfeff9\ -- Root folder for "Items" table|-e943c1e6…5fc1f5\ -- Folder for "ItemImage" columnListing 2-20:Sample <strong>FILESTREAM</strong> data container structure.75

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

Saved successfully!

Ooh no, something went wrong!