Advertisements

Category Archives: SQL Server 2005

Moving SQL Datafile to alternate location in SQL Server 2005

  use master
   go
   sp_detach_db ‘mydb’
   go
  • Copy the data files and the log files from the current location (D:\folder1\Data) to the new location (E:\folder2).
  • Reattach the database. Point to the files in the new location as follows:
use master
  go
sp_attach_db ‘mydb’,’E:\folder2\mydbdata.mdf’,’E:\folder2\mydblog.ldf’
  go

 

To verify that the change has taken place; run the below command

use mydb
   go
   sp_helpfile
   go

The filename column values should reflect the new locations.

Advertisements