About this question
I have a database and want to move the .mdf and .ldf files to another location. But I do not want to stop the MSSQLSERVER service, and I do not want to export to another server. How can I do this?
I have a database and want to move the .mdf and .ldf files to another location. But I do not want to stop the MSSQLSERVER service, and I do not want to export to another server. How can I do this?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Salesforce Expert
Answered on Aug 21, 2021
Here are the steps to move SQL Server System Database Files - Part 1
You don't have to stop the SQL Server service to move database files, but you do have to take the specific database offline. This is because you can't move files while they're being accessed and taking the database offline stops the files from being used by the SQL Server application. The process to move them is fairly simple. Detach/Attach was already described, but it is not nearly this complex. Change the file locations with an ALTER DATABASE command: USE master; --do this all from the master ALTER DATABASE foo MODIFY FILE (name='DB_Data1' ,filename='X:\NewDBFile\DB_Data1.mdf'); --Filename is new location Note, you do not need to declare the old location in this command. Changing this path does not take effect immediately, but will be used the next time the database starts up.Set the database offline (I use WITH ROLLBACK IMMEDIATE to kick everyone out and rollback all currently open transactions) ALTER DATABASE foo SET OFFLINE WITH ROLLBACK IMMEDIATE; Move/Copy the files to the new location Just copy the files over using your favorite method (Click 'n Drag, XCopy, Copy-Item, Robocopy) Bring the database online
ALTER DATABASE foo SET ONLINE;
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Salesforce guides from industry experts
Common Salesforce interview questions, answered
Guides, tips and career advice on Salesforce from JanBask experts.
Salesforce How to Get Into Salesforce With No Experience
Wondering if you can get a Salesforce job with no experience? Learn how to pick a career path, build real skills, and land your…
Salesforce How to Become a Salesforce Developer Without Experience
No coding background? Learn how to become a Salesforce Developer step by step - skills to build, projects to create, and how to…
Salesforce How to Become a Salesforce Admin With No Experience
No Salesforce Admin experience? Learn how to build real skills, create projects, and land an entry-level Salesforce Admin job…
Salesforce How Long Does It Take to Become a Salesforce Developer?
Wondering how long to learn Salesforce Developer? Most beginners need 6–12 months. See the study time, stage-by-stage roadmap and…