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

Popular posts from this blog

Metastorm - Open form in an action from a list or link

Corporate Intranet Information Architecture – a Publishing Site

No Search Results in SharePoint Contextual Search OSSSearchResults.aspx