Problem: Whenever we try to rename a database and is it is in use we got the error Resolution: best way to use the T-SQL Code to do the same. Code is given below: --- To rename the database while active connection are available ALTER DATABASE [ ] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO sp_renamedb ' ' , ' ' GO ALTER DATABASE [ ] SET MULTI_USER GO For Example --- To rename the database while active connection are available ALTER DATABASE [Test] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO sp_renamedb 'Test' , 'Test1' Go ALTER DATABASE [Test1] SET MULTI_USER GO