Tuesday, August 14, 2012

How can I move my database files in SQL Server?


  • 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

No comments: