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>With this in mind, let's get started! If you have followed all the sample scripts so farand executed them in SSMS, you will have a <strong>FILESTREAM</strong>-enabled table containinga <strong>FILESTREAM</strong> column. So, before we move ahead with storing BLOB data in the<strong>FILESTREAM</strong> column <strong>of</strong> our table, let us rebuild it to make sure that everything is set upcorrectly (Listing 2-17).-- Drop the table if existsIF OBJECT_ID('Items', 'U') IS NOT NULLBEGINDROP TABLE ItemsENDGO-- Create the tableCREATE TABLE [dbo].[Items]([ItemID] UNIQUEIDENTIFIER ROWGUIDCOLNOT NULLUNIQUE ,[ItemNumber] VARCHAR(20) ,[ItemDescription] VARCHAR(50) ,[ItemImage] VARBINARY(MAX) <strong>FILESTREAM</strong>NULL)GOListing 2-17:Creating a table with a <strong>FILESTREAM</strong> column.<strong>SQL</strong> <strong>Server</strong> 2005 enhanced the OPENROWSET() function with a very powerful attribute:BULK. <strong>The</strong> BULK attribute can be used to load the content <strong>of</strong> an image file on disk into aVARBINARY(MAX) column, and then insert it into a <strong>FILESTREAM</strong> column.We'll use the BULK attribute to load the image <strong>of</strong> a Micros<strong>of</strong>t mouse (Figure 2-4) into the<strong>FILESTREAM</strong> column <strong>of</strong> the Items table. (You can find this image in the sample imagedownload file available at http://brurl.com/fs4 and extract it into C:\TEMP folder if youdo not want to change the code given in the sample snippet.)73

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

Saved successfully!

Ooh no, something went wrong!