Are you looking for customized advices? Click here to contact the expert!
by
2
6
3,881
6
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 2287th place
Created
Modified Oct 25, 2014
Architecturex86_64
DBMSMS SQL Server
LanguageT-SQL
LicenseMIT_X11
OSWindows

Move a file to another location in SQL Server

Here is the procedure to move a file to another location (e.g. for the database called MyDB).
First you need to execute the first part of this snippet (until the comment '/**** Now you need to physically move the file to the other location ***/').
Then you need to move the file and eventually you can execute the last two statements.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/206184/Move-a-file-to-another-location-in-SQL-S?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE MyDB SET OFFLINE; ALTER DATABASE MyDB MODIFY FILE ( Name = MyDB_file1, Filename = 'c:\DB\MyDB.mdf' ); /**** Now you need to physically move the file to the other location ***/ ALTER DATABASE MyDB SET ONLINE; ALTER DATABASE MyDB SET MULTI_USER;
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus