Thursday, May 21, 2020

HOW TO MOVE DATAFILES IN SQL SERVER

1. Set database offline

USE master

ALTER DATABASE STG SET OFFLINE;

-- 2. Move the file or files to the new location

ALTER DATABASE STG MODIFY FILE ( NAME = STG, FILENAME = 'F:\SQL_DATABASES\STG.mdf' );

-- 3. Set database online

ALTER DATABASE STG SET ONLINE;

SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'STG');

exec sp_helpdb 'STG'

No comments:

Post a Comment