Pages

Thursday, May 12, 2022

Rename files in SQL Server

USE [master];
GO
--Disconnect all existing session.
ALTER DATABASE jiradev4 SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

--Change database in to OFFLINE mode.
ALTER DATABASE jiradev4 SET OFFLINE
GO

ALTER DATABASE jiradev4 MODIFY FILE (Name='jiradev4', FILENAME='D:\DB\jiradev4.mdf')
GO

ALTER DATABASE jiradev4 MODIFY FILE (Name='jiradev4_log', FILENAME='D:\Logs\jiradev4_log.ldf')
GO

Here - physically rename datafiles on server to the new names

ALTER DATABASE jiradev4 SET ONLINE
Go
ALTER DATABASE jiradev4 SET MULTI_USER
Go

Refresh the databases list, and check the database properties.

No comments:

Post a Comment