Move Data/logfiles of a Live SQL Server to new location

Sometimes its needed to be able to move a log file etc on a live and running instance.
To do so use the Managementstudio to run some SQL scripts.

ALTER DATABASE "AI2018_Inventor IDF"  
MODIFY FILE (NAME ="AI2016_Inventor IDF_log", FILENAME = 'E:\DatabaseLogfiles\AI2018_Inventor IDF_log.ldf');

-- Set database to online too try again of you forgott to move the file ;)
-- User the full samt of the service account nt Service\MSSSQL$instance... for folder rights...
ALTER DATABASE Vault IDF SET ONLINE;


-- Verify file location and status!
SELECT name, physical_name AS NewLocation, state_desc AS OnlineStatus
FROM sys.master_files  
WHERE database_id = DB_ID(N'Vault')  
GO

Userrights might be a issue and just to remember:
When using the default service account and you need to give it new folder rights the syntax for adding the account is ”NT Service\Accountname”

Lämna ett svar