DBA Tips Archive for SQL Server
No Title[an error occurred while processing this directive]
by Jeff Hunter, Sr. Database Administrator
Moving a FILESTREAM-enabled database is very similar to moving a user database. The method used to move a FILESTREAM-enabled database includes detaching the database, moving the physical files and FILESTREAM data container, and then bringing the database back online with the CREATE DATABASE command and the FOR ATTACH and CONTAINS FILESTREAM options.
This guide shows the steps necessary to move a FILESTREAM-enabled database within the same instance using SQL Server 2008 R2 and Transact-SQL as part of a planned relocation or scheduled maintenance operation. For more information on how to move user databases and system databases in SQL Server, see the following articles:
To work through the example demonstrated in this article, you will obviously need to have a FILESTREAM-enabled database. This guide will use the AdventureWorks2008R2 sample database which is part of the AdventureWorks 2008R2 sample databases installation.
Click here for step-by-step instructions on how to install the AdventureWorks 2008R2 sample databases. You can also find a guide on how to create a FILESTREAM-enabled database on Microsoft's Developer Network (MSDN).
The following example moves one the FILESTREAM-enabled AdventureWorks sample databases named AdventureWorks2008R2 to a different directory location in the same SQL Server instance using the Detach/Attach method. The AdventureWorks2008R2 database contains one data file, AdventureWorks2008R2_Data.mdf, one log file, AdventureWorks2008R2_Log.ldf, and one FILESTREAM Data Container Documents2008R2; all of which are currently located in the F:\MSSQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA directory path.
The name of the FILESTREAM filegroup is Document2008R2FileStreamGroup which will be needed when we bring the database back online later in this section.
The data file and FILESTREAM directory will be relocated to G:\MSSQL\Data while the log file will be moved to L:\MSSQL\Log.
Detach the database.
Next, move the data files, FILESTREAM directory, and the log files from the current location (F:\MSSQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA) to the new location (G:\MSSQL\Data for data files and FILESTREAM directory and L:\MSSQL\Log for log files).
Re-attach the database and point to the files in the new location using the CREATE DATABASE command with the FOR ATTACH and CONTAINS FILESTREAM option.
After bringing the database online, verify the change in file locations by querying the the sys.master_files system-wide view.
Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: http://www.iDevelopment.info. Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.
Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at firstname.lastname@example.org.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.
Last modified on
Saturday, 23-Mar-2013 18:50:13 EDT
Page Count: 9279