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>As such, the following steps are required, in case you want to convert an existingVARBINARY(MAX) column to <strong>FILESTREAM</strong>.1. Create a new VARBINARY(MAX) column with the <strong>FILESTREAM</strong> attribute.2. Copy the data from the VARBINARY(MAX) column to the <strong>FILESTREAM</strong> column usingan UPDATE statement. This will create a <strong>FILESTREAM</strong> file for each non-NULL valuebeing copied to the new column.3. Drop the original VARBINARY(MAX) column.4. Rename the new <strong>FILESTREAM</strong> column to the original name.<strong>The</strong> T-<strong>SQL</strong> script in Listing 2-13 demonstrates how to do this.-- Add <strong>FILESTREAM</strong> columnALTER TABLE [dbo].[Items]ADD ItemImage_New VARBINARY(MAX) <strong>FILESTREAM</strong> NULL-- Copy data to the new columnUPDATE [dbo].[Items] SETItemImage_New = ItemImage-- Drop the original columnALTER TABLE [dbo].[Items]DROP COLUMN ItemImage-- Rename the new column to original nameEXECUTE sp_rename@objname = '[dbo].[Items].[ItemImage_New]',@newname = 'ItemImage',@objtype = 'COLUMN'Listing 2-13:Altering a VARBINARY(MAX) column to a <strong>FILESTREAM</strong> column.A similar approach can be used to change a <strong>FILESTREAM</strong> column to a regularVARBINARY(MAX) column.67

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

Saved successfully!

Ooh no, something went wrong!