Rename Database – AumTechHub.Com http://aumtechhub.com Just share it!!! Tue, 23 Nov 2021 01:54:19 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 179596041 Rename Database By closing connections http://aumtechhub.com/rename-database-by-closing-connections/?utm_source=rss&utm_medium=rss&utm_campaign=rename-database-by-closing-connections Tue, 25 Aug 2020 02:49:39 +0000 http://aumtechhub.com/?p=19 When trying to rename database with open database connections its always a pain as the admin has to kill those connections. Instead of going that route one can use the following code.

USE [master]
GO
ALTER DATABASE NameOfYourDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE NameOfYourDatabase
Modify Name = NewNameOfYourDatabase
GO
ALTER DATABASE NewNameOfYourDatabase SET MULTI_USER;

Note: Name of the database in the query above is case sensitive.

]]>
19