roberto
6/14/2018 - 10:53 AM

Force DB rename or delete

Commands to force operations on db in use

-- Force rename
USE [master]
GO
ALTER DATABASE DB_TO_RENAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE DB_TO_RENAME MODIFY NAME = NEW_NAMEOF_DB;
GO
-- other useful commands
ALTER DATABASE DB_TO_RENAME SET READ_ONLY;
GO
ALTER DATABASE DB_TO_RENAME SET MULTI_USER;
GO
-- Force db drop
USE [master]
GO
ALTER DATABASE [DbNameToDrop] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE [DbNameToDrop]
GO