Menu
header photo

SQL-Talk

Talks all about SQL Server and Azure

Moving database using Offline and Online method

/* How to move files of database using offline/online
To move files into D:\MSSQL\CollegeDB_Files*/

--Step1: Check current path 
sp_helpdb CollegeDB
--Step2: Create new folder and update the new path
alter database CollegeDB
modify file
(name='CollegeDB',filename='D:\MSSQL\CollegeDB_Files\CollegeDB.mdf')
alter database CollegeDB
modify file
(name='CollegeDB_log',filename='D:\MSSQL\CollegeDB_Files\CollegeDB_log.ldf')
--Step3: Take database offline
use master
go
alter database CollegeDB set offline
--Step4: We can move the files into new path
--Step5: Bring database online
alter database CollegeDB set online
--Step6: Check the new path
sp_helpdb CollegeDB