Move a SQL database data (.mdf) and log (.ldf) files.
--Get Current LDF, MDF locations.
use WSS_Content_YourDB
go
sp_helpfile
go
--Close all other connections and detach drive Detach Drive
ALTER DATABASE WSS_Content_YourDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
use master
go
sp_detach_db 'WSS_Content_YourDB'
go
--Do not close this window
----------------------------------
-------------Move File------------
----------------------------------
--Attch Database and renable all conections
use master
go
sp_attach_db 'WSS_Content_YourDB','C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\WSS_Content_YourDB.mdf','C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Data\WSS_Content_YourDB_log.ldf'
go
ALTER DATABASE WSS_Content_YourDB SET MULTI_USER WITH ROLLBACK IMMEDIATE
GO
------------------------------------
Comments
Post a Comment