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 2: Getting Started with <strong>FILESTREAM</strong>Note that the file locations in which <strong>SQL</strong> <strong>Server</strong> stores the BLOB data are irrelevant to us,because no direct access to these files is recommended. Any read/write operation to theBLOB data should be done either through T-<strong>SQL</strong> (in which you access the BLOB data asif it is a VARBINARY(MAX) column in the table) or through the Win32 API (in which youaccess the BLOB data using a logical identifier). This chapter provides examples usingT-<strong>SQL</strong>, and the Win32 API is discussed further in Chapter 3: Accessing <strong>FILESTREAM</strong> Datafrom Client Applications.Using T-<strong>SQL</strong> to add <strong>FILESTREAM</strong> columns to anexisting tableAdding a <strong>FILESTREAM</strong> column to an existing table can be simple or complex, dependingupon the current schema <strong>of</strong> the table. In the simplest case, the ALTER TABLE commandcould be as shown in Listing 2-9.ALTER TABLE [dbo].[Items]ADD ItemImage VARBINARY(MAX) <strong>FILESTREAM</strong> NULLGOListing 2-9:ALTER TABLE T-<strong>SQL</strong> script to add a <strong>FILESTREAM</strong> column to an existing table.This script adds a new <strong>FILESTREAM</strong> column named ItemImage to the Items table.For the script to execute successfully, the table must already have a UNIQUEIDENTIFIERcolumn that meets all requirements outlined above.In most cases, you can look into the table schema to verify whether or not the tablealready has a UNIQUEIDENTIFIER column with the required characteristics. <strong>The</strong> easiestway may be to right-click on the table in SSMS and generate the CREATE script for thetable. You can see the current attributes <strong>of</strong> all the columns in the script output.63

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

Saved successfully!

Ooh no, something went wrong!