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 7: <strong>FILESTREAM</strong> Database AdministrationUSE NorthPoleGOCREATE TABLE [dbo].[Items]([ItemID] [int] IDENTITY(1,1) NOT NULL,[ItemGuid] [uniqueidentifier] ROWGUIDCOL NOT NULL UNIQUE,[ItemNumber] [varchar](20) NULL,[ItemDescription] [varchar](50) NULL,[ItemImage] [varbinary](max) <strong>FILESTREAM</strong> NULL,CONSTRAINT PKEY_Items PRIMARY KEY CLUSTERED([ItemID] ASC))Listing 7-19:Creating a <strong>FILESTREAM</strong> table.This table is a bit different from the previous examples; this time, the Items table has anIDENTITY column called ItemID, which has a PRIMARY KEY defined on it. <strong>The</strong> next stepis to insert a few rows into the table (Listing 7-20).INSERT INTO Items(ItemGuid, ItemNumber, ItemDescription, ItemImage) VALUES(NEWID(), 'ITM001', 'Item 1', 0x),(NEWID(), 'ITM001', 'Item 1', 0x)Listing 7-20:Populating the table with zero-length files.In this simple example, there will only be two files in the <strong>FILESTREAM</strong> data container.However, imagine that the database has grown very large and the folder contains a largenumber <strong>of</strong> <strong>FILESTREAM</strong> data files, necessitating the move <strong>of</strong> the <strong>FILESTREAM</strong> filegroupto a new disk volume. For the purpose <strong>of</strong> keeping this example simple, let's assume thatthe new location is C:\<strong>Art</strong>OfFS\Demos\Chapter7\NorthPole_fs2. Of course, inreality, the new location would be on a separate disk volume.<strong>The</strong> approach we will take here is to add a new <strong>FILESTREAM</strong> filegroup at this newlocation, and rebuild the clustered index on the <strong>FILESTREAM</strong> table, which will move the<strong>FILESTREAM</strong> data to this new location. Listing 7-21 adds a new <strong>FILESTREAM</strong> filegroupinto the NorthPole database.296

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

Saved successfully!

Ooh no, something went wrong!