[MSSQL] Alter DBName

  • 59
  • 0

MSSQL Alter DBName

USE [master]
GO  
ALTER DATABASE [XXX] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE [XXX] MODIFY NAME=[YYY] ;
GO  
ALTER DATABASE [YYY] MODIFY FILE (NAME=SWH_data, NEWNAME=YYY_data );
GO
ALTER DATABASE [YYY] MODIFY FILE (NAME=SWH_log, NEWNAME=YYY_log );
GO
ALTER DATABASE [YYY] SET OFFLINE
GO
--Rename Physical Filename
ALTER DATABASE [YYY] MODIFY FILE (Name='YYY_data', FILENAME='E:\SQLData\YYY.mdf')
GO
ALTER DATABASE [YYY] MODIFY FILE (Name='YYY_log', FILENAME='E:\SQLData\YYY_Log.mdf')
GO
ALTER DATABASE [YYY] SET ONLINE
GO
ALTER DATABASE [YYY] SET MULTI_USER
GO