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 7: <strong>FILESTREAM</strong> Database Administration-- Detach the databaseUSE masterGOEXEC sp_detach_db @dbname = 'NorthPole'Listing 7-4:Detaching a <strong>FILESTREAM</strong>-enabled database.Next, locate the primary data file, log file and <strong>FILESTREAM</strong> data container, and movethem to their new locations. Now we're ready to reattach the database to our <strong>SQL</strong> <strong>Server</strong>instance. This could be the same instance, a different instance on the same computer, ora different instance on a different computer. Note, though, that if the database is beingattached to a different <strong>SQL</strong> <strong>Server</strong> instance, we must ensure that <strong>FILESTREAM</strong> is enabledon the target server (see Appendix A) and that the target <strong>SQL</strong> <strong>Server</strong> instance should berunning the same, or a later, version <strong>of</strong> <strong>SQL</strong> <strong>Server</strong>. You can detach a <strong>SQL</strong> <strong>Server</strong> 2008and attach it to a <strong>SQL</strong> <strong>Server</strong> 2012 instance, but you cannot detach a <strong>SQL</strong> <strong>Server</strong> 2012database and attach it to a <strong>SQL</strong> <strong>Server</strong> 2008/R2 instance.Once these files have been moved to the new location, we are ready to attach the databaseas shown in Listing 7-5.-- Attach the <strong>FILESTREAM</strong> databaseCREATE DATABASE NorthPole ONPRIMARY (NAME = NorthPole,FILENAME = 'C:\Temp\Data\NorthPole.mdf'),FILEGROUP NorthPole_fs CONTAINS <strong>FILESTREAM</strong>(NAME = NorthPole_fs,FILENAME = 'C:\Temp\FS\NorthPole_fs')LOG ON (NAME = NorthPole_log,FILENAME = 'C:\Temp\Data\NorthPole_log.ldf')FOR ATTACHGOListing 7-5:Attaching a <strong>FILESTREAM</strong>-enabled database.To verify success, connect to the NorthPole database and fire <strong>of</strong>f a simple query toretrieve the data from the items table.278

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

Saved successfully!

Ooh no, something went wrong!