Plataan - Microsoft Dynamics - Learning & Competence Management Vincent Bellefroid Koen Stox Steven Renders Conny Schuddinck Steffie Alexiou
A blog about Microsoft Dynamics
Home Archives Subscribe Plataan website

« Key Groups and new functions. | Main | What’s the difference between using @ and # when opening a dialog window? »


How can I move my database files in SQL Server?

This is a question I got asked a few times the last few months, so why not write a little blog article about it.

An easy way to move user database files to a different location is by detaching, moving and attaching the user database.

(Of course, while you are doing this, people will not be able to work in the database. Make sure they logout of Dynamics NAV correctly.)

This database move can be done in SQL Server Management Studio (SSMS) so you don't have to type any code:

  • Start SQL Server Management Studio
  • Expand the server instance, expand Databases
  • Right-click the database you want to move, and choose "Properties"
  • In the Properties window, choose "Files" and write down the current file paths. Click "Cancel"
  • Right-click the database again, and choose "Tasks - Detach..."
  • Click "OK" in the next window
  • Use Windows Explorer to move the data and log files (.mdf and .ldf) to the new location
  • Right-click Databases, and choose "Attach..."
  • In the "Attach databases" window, click "Add"
  • In the "Locate database files" window, browse to the new location and select the .mdf file. Click "OK"
  • In the details pane, verify that the new location is listed for both the .mdf and the .ldf file. Click "OK"
  • In SQL Server Management Studio, choose "View - Refresh" and verify that your database is listed again under Databases

Alternatively you can back up the database, within Sql Server, and restore it, specifying a different location for the files on the options table or use the MOVE clause in the RESTORE command in Transact-SQL:

How to move SQL Server databases to a new location by using Detach and Attach functions in SQL Server


Thank you so very much for the post,this was very helpful!!!

The comments to this entry are closed.

October 2011

Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Plataan Community

Visit us on LinkedIn Visit us on Facebook Visit us on Twitter