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 AdministrationDetaching and Attaching <strong>FILESTREAM</strong>DatabasesIt is common practice to detach and attach database files in order to move a databasefrom one location to another. In a typical detach-attach process, you detach the database,move the MDF and LDF files to the new location, and then perform an attach operation.<strong>The</strong> only difference for a <strong>FILESTREAM</strong>-enabled database is that, along with your data(MDF) and log (LDF) files, you also need to move the <strong>FILESTREAM</strong> data container.SSMS does not fully support attaching <strong>FILESTREAM</strong>-enabled databases<strong>The</strong> Attach Databases dialog box does not allow you to specify the location <strong>of</strong> the <strong>FILESTREAM</strong> datafile. As a result, you cannot attach a <strong>FILESTREAM</strong>-enabled database using SSMS if the path to the<strong>FILESTREAM</strong> container is different from the original location.Let's see this in action. Listing 7-3 re-creates our, by now familiar, NorthPole databaseand loads an image into a <strong>FILESTREAM</strong> column. As usual, change the locations and pathsas required.USE masterGO-- If the sample database exists, drop it and re-create itIF DB_ID('NorthPole') IS NOT NULLDROP DATABASE NorthPoleGOCREATE DATABASE NorthPole ON PRIMARY (NAME = NorthPole,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter7\NorthPole.mdf'), FILEGROUP NorthPole_fs CONTAINS <strong>FILESTREAM</strong>(NAME = NorthPole_fs,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter7\NorthPole_fs') LOG ON (NAME = NorthPole_log,FILENAME = 'C:\<strong>Art</strong>OfFS\Demos\Chapter7\NorthPole_log.ldf')GO276

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

Saved successfully!

Ooh no, something went wrong!